i have a project that i make a 3 trafic light with 9LED, and i integrated with a railroad crossing (servo) and than a push button as a input, my plan is when i push the button once its move the servo into 0-90 degree and the light only the red colour high, than if i push the button twice, its move the servo into 0-90 degree and the light have a 3 fase of colour pattern, and my plan the pattern didnt stop or keep looping, except i push the button again.
now my problem is when i push the button twice, the led stop at the third pattern.
my question is how to make my project always looping ?
#include <Servo.h>
Servo servo;
int button= 12;
int nilaitombol;
int count;
int ledDelay = 300;
int redPin = 11;
int yellowPin = 10;
int bluePin = 9;
int merah = 8;
int kuning = 7;
int hijau = 6;
int bereum = 5;
int koneng = 4;
int hejo = 3;
void setup(){
servo.attach(13);
pinMode(redPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
pinMode(bluePin, OUTPUT);
pinMode(merah, OUTPUT);
pinMode(kuning, OUTPUT);
pinMode(hijau, OUTPUT);
pinMode(bereum, OUTPUT);
pinMode(koneng, OUTPUT);
pinMode(hejo, OUTPUT);
pinMode(button, INPUT);
}
void loop(){
nilaitombol= digitalRead(button);
if(nilaitombol == 1){
count++;
delay(300);
if(count==1){
digitalWrite(kuning, LOW);digitalWrite(koneng, LOW); digitalWrite(bluePin, LOW);
digitalWrite(redPin, HIGH);
digitalWrite(merah, HIGH);
digitalWrite(bereum, HIGH);
servo.write (90);
delay(2000);
servo.write (0);
}
if(count==2){
servo.write (0);
delay(2000);
servo.write (90);
digitalWrite(redPin, LOW);
digitalWrite(merah, LOW);
digitalWrite(bereum, LOW);
digitalWrite(bluePin, HIGH); digitalWrite(merah, HIGH);digitalWrite(bereum, HIGH); // jalan yos sudarso-madiun(hijau), jln prambanan-nganjuk (merah), jln yos sudarso-nganjuk(merah)
digitalWrite(redPin, LOW); digitalWrite(kuning, LOW); digitalWrite(koneng, LOW);
delay(900);delay(1400); delay(2000); // tunda beberapa milisecond
digitalWrite(redPin, HIGH); digitalWrite(hijau, HIGH);digitalWrite(hejo, HIGH);
digitalWrite(merah, LOW);digitalWrite(bereum, LOW); digitalWrite(bluePin, LOW); //
delay(ledDelay); delay(1500);delay(900);// tunda 3 detik
digitalWrite(bluePin, HIGH); digitalWrite(kuning, HIGH);digitalWrite(koneng, HIGH);//
digitalWrite(redPin, LOW); digitalWrite(yellowPin, LOW); digitalWrite(hijau, LOW); digitalWrite(hejo, LOW); //
delay(2000); delay(ledDelay); delay(ledDelay);//
count=0;
}
}
}