#define Red 10
#define Yellow 9
#define Green 8
#define Sensor 7
int val = 0;
int prevVal=0;
void setup()
{
pinMode(Red, OUTPUT);
pinMode(Yellow, OUTPUT);
pinMode(Green, OUTPUT);
pinMode(Sensor, INPUT_PULLUP);
digitalWrite(Red, LOW);
digitalWrite(Yellow, LOW);
digitalWrite(Green, LOW);
}
void loop()
{
digitalWrite(Green, LOW);
val = digitalRead(Sensor);
if (val == LOW && prevVal==HIGH)
{
digitalWrite(Green, LOW);
digitalWrite(Yellow, HIGH);
delay(2000);
digitalWrite(Yellow, LOW);
digitalWrite(Red, HIGH);
}
if(val==HIGH)
{
digitalWrite(Red, LOW);
digitalWrite(Yellow, LOW);
digitalWrite(Green, HIGH);
}
// delay(20); poor man's debounce
prevVal=val;
}