Hello group, I'm pretty new in Arduino, recently I made this project that through a button will count and blink a led.
1st and second time go to flash green
3rd time got to flash blue
4th time got to flash green
5th time got to flash red
The problem: the counter don't work, it goes 0, 1, 3, 5 don't know why.
int count = 0;
boolean button = false;
void setup() {
pinMode(11,OUTPUT);// put your setup code here, to run once:
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
pinMode(2,INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
button = digitalRead(2);
if (button == 0 && (count == 0 || count == 1 || count == 3)){
digitalWrite(12, HIGH);
delay(200);
digitalWrite(12,LOW);
count = count + 1;
}
if ( button == 0 && count == 2){
digitalWrite(12, LOW);
digitalWrite(13, HIGH);
delay(200);
digitalWrite(13,LOW);
count = count + 1;
}
if( button == 0 && count == 4){
digitalWrite(12,LOW);
digitalWrite(13,LOW);
digitalWrite(11,HIGH);
delay(200);
digitalWrite(11,LOW);
count = 0;
}
digitalWrite(11,LOW);
digitalWrite(12,LOW);
digitalWrite(13,LOW);
}
THANK YOU FOR THE HELP