Hi, me again!
i have sorted all the electronics out and there seems to be a problem somewhere, starting off with the code i am just checjing through everything. is there anyone on here that could check this code for me. thank you. i want the script to do the following : switch pin 8 high for 5 seconds when any of the pins 9, 10, 11 and 12 are high. (high being 5 volts from the reed switch). thank you
// Define the pins
const int pin9 = 9;
const int pin10 = 10;
const int pin11 = 11;
const int pin12 = 12;
const int outputPin = 8;
// State variables
bool isOutputHigh = false;
unsigned long outputStartTime = 0; // To track how long pin 8 is HIGH
void setup() {
// Set input pins
pinMode(pin9, INPUT);
pinMode(pin10, INPUT);
pinMode(pin11, INPUT);
pinMode(pin12, INPUT);
// Set output pin
pinMode(outputPin, OUTPUT);
// Ensure the output starts LOW
digitalWrite(outputPin, LOW);
}
void loop() {
// Check if any of the input pins is HIGH
if (digitalRead(pin9) == HIGH || digitalRead(pin10) == HIGH ||
digitalRead(pin11) == HIGH || digitalRead(pin12) == HIGH) {
// If pin 8 is not already HIGH, activate it and record the time
if (!isOutputHigh) {
digitalWrite(outputPin, HIGH);
isOutputHigh = true;
outputStartTime = millis(); // Record the time pin 8 was set HIGH
}
}
// Check if pin 8 has been HIGH for 5 seconds
if (isOutputHigh && millis() - outputStartTime >= 5000) {
digitalWrite(outputPin, LOW); // Turn off pin 8 after 5 seconds
isOutputHigh = false; // Reset the state
}
}