I'm trying get a password system working that when you click 3 buttons in a certain order (1, 2, 3, 3, 1) then an LED will light up. But as I'm going to implement this into a larger code I can't just have the void loop() going forever to wait for it.
I think my issue is in the while loops and making it wait for one of the buttons to be pressed but I don't know how to get it to work.
thanks
#define greenLED A0
#define redLED A1
int button1 = 5;
int button2 = 4;
int button3 = 3;
void setup() {
// put your setup code here, to run once:
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
pinMode(button3, INPUT_PULLUP);
}
void loop() {
// put your main code here, to run repeatedly:
int total = 0;
while(digitalRead(button1) == LOW && digitalRead(button2) == LOW && digitalRead(button3) == LOW){
while(digitalRead(button1) == LOW && digitalRead(button2) == LOW && digitalRead(button3) == LOW){
while(digitalRead(button1) == LOW && digitalRead(button2) == LOW && digitalRead(button3) == LOW){
while(digitalRead(button1) == LOW && digitalRead(button2) == LOW && digitalRead(button3) == LOW){
while(digitalRead(button1) == LOW && digitalRead(button2) == LOW && digitalRead(button3) == LOW){
if(digitalRead(button1) == HIGH){
total = total + 1;
}
}
if(digitalRead(button2)==HIGH){
total = total+1;
}
}
if(digitalRead(button3)==HIGH){
total = total + 1;
}
}
if(digitalRead(button3)==HIGH){
total = total+1;
}
}
if(digitalRead(button1) == HIGH){
total = total+1;
}
}
if(total == 5){
digitalWrite(A0, HIGH);
delay(2000);
digitalWrite(A0, LOW);
}else{
digitalWrite(A1, HIGH);
delay(2000);
digitalWrite(A1, LOW);
}
}