Hi
I'm struggeling with a simple code with 2 inputs and 3 outputs. My code does something weird.
Output pins: 2,3,4
Input pins 5,6
Pseudo code:
All pins are initialli LOW
If pin 5 changes from LOW to HIGH (toggle switch)
Switch pin 2 to HIGH
wait 5s
switch pin 2 to LOW
wait 5s
switch pin3 to HIGH
wait 5s
switch pin3 to LOW
If pin 6 changes from LOW to HIGH (toggle switch)
Switch pin 2 to HIGH
wait 5s
switch pin 2 to LOW
wait 5s
switch pin4 to HIGH
wait 5s
switch pin4 to LOW
Here is to real code:
int outputPin2 = 2;
int outputPin3 = 3;
int outputPin3 = 4;
int inputPin5 = 5;
int inputPin6 = 6;
int reading_inputPin5;
int reading_inputPin6;
// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0; // the last time the output pin was toggled
long debounce = 200; // the debounce time, increase if the output flickers
void setup()
{
pinMode(outputPin2, OUTPUT);
pinMode(outputPin3, OUTPUT);
pinMode(outputPin4, OUTPUT);
pinMode(inputPin5, INPUT);
pinMode(inputPin6, INPUT);
}
void loop()
{
reading_inputPin5 = digitalRead(inputPin5);
reading_inputPin6 = digitalRead(inputPin6);
if (reading_inputPin5 == HIGH && millis() - time > debounce) {
time = millis();
digitalWrite(outputPin2, HIGH);
delay(5000); // pauses for 5s
digitalWrite(outputPin2, LOW);
delay(5000); // pauses for 5s
digitalWrite(outputPin3, HIGH);
delay(5000); // pauses for 5s
digitalWrite(outputPin3, LOW);
}
else if (reading_inputPin6 = HIGH && millis() - time > debounce) {
time = millis();
digitalWrite(outputPin2, HIGH);
delay(5000); // pauses for 5s
digitalWrite(outputPin2, LOW);
delay(5000); // pauses for 5s
digitalWrite(outputPin4, HIGH);
delay(5000); // pauses for 5s
digitalWrite(outputPin4, LOW);
}
else {
}
}
Thanks for your help