I'm quite new to Arduino and the programming of the board, but I wanted to have a go at making a traffic light based on an example I found online.
The example supplied a simple layout which I roughly copied with the components I had.
I then created the following code to mimic the traffic lights of my local area.
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 on, other off for 3 seconds
digitalWrite(green,LOW);
digitalWrite(yellow,LOW);
digitalWrite(red,HIGH);
delay(3000);
// red on, amber on,green off for 3 seconds
digitalWrite(green,LOW);
digitalWrite(yellow,HIGH);
digitalWrite(red,HIGH);
delay(3000);
// red off, amber off,green on for 3 seconds
digitalWrite(green,HIGH);
digitalWrite(yellow,LOW);
digitalWrite(red,LOW);
delay(3000);
// red off, amber on,green on for 3 seconds
digitalWrite(green,HIGH);
digitalWrite(yellow,HIGH);
digitalWrite(red,LOW);
delay(3000);
}
What I'm wanting to achieve next is a button which resets the code back to the top of void changeLights.
I assume I would be able to do this using a push-to-make switch, but I'm not sure how to incorporate it into my circuit or if it is even possible to reset using this.
