Traffic Light
From SainSmart Wiki
Contents
Traffic light
Experiment component:
- Red , Green , Yellow led lamp: 3
- 220Ω resistor: 3
- Breadboard & Jumper wires
Connect your circuit as the below diagram.
Example code:
Program code is in the traffic lights program folder. Double-click to open and you will find out a trafficLed.pde file. Double-click the icon to open it. Then you will see that it is the arduino programming software window with the experimental program code.
int ledred=10; //define digital pin10 red int ledyellow=7; //define digital pin7 yellow int ledgreen=4; //define digital pin4 green void setup() {
pinMode(ledred,OUTPUT);//set red pin output pinMode(ledyellow,OUTPUT);// set yellow pin output pinMode(ledgreen,OUTPUT);// set green pin output
} void loop() {
digitalWrite(ledred,HIGH);//light up red lamp delay(1000);//delay 1000 ms = 1 s digitalWrite(ledred,LOW);//go out red lamp digitalWrite(ledyellow,HIGH);//light up yellow lamp delay(200);//delay 200 ms// digitalWrite(ledyellow,LOW);//go out digitalWrite(ledgreen,HIGH);//light up green lamp delay(1000);//delay 1000 ms digitalWrite(ledgreen,LOW);//go out
}