Red (5s)
Red + Yellow (2s)
Green (5s)
Yellow (2s)
Red (5s)... loop back again
The sample code:
int red = 13; int yellow = 12; int green = 11;
void setup(){
pinMode(red,OUTPUT);
pinMode(yellow,OUTPUT);
pinMode(green,OUTPUT);
}
void loop(){
changeLights();
}
void changeLights(){
//red first
digitalWrite(red,HIGH);
digitalWrite(green,LOW);
digitalWrite(yellow,LOW);
delay(5000);
//red + yellow
digitalWrite(red,HIGH);
digitalWrite(yellow,HIGH);
digitalWrite(green,LOW);
delay(2000);
//green
digitalWrite(red,LOW);
digitalWrite(yellow,LOW);
digitalWrite(green,HIGH);
delay(5000);
//yellow
digitalWrite(red,LOW);
digitalWrite(yellow,HIGH);
digitalWrite(green,LOW);
delay(2000);
}
No comments:
Post a Comment