Difference between revisions of "Traffic Light"
From SainSmart Wiki
(Created page with "= Traffic light = == Experiment component: == *Red , Green , Yellow led lamp: 3 *220Ω resistor: 3 *Breadboard & Jumper wires == Connect your circuit as the below diagram. =...") |
(→Connect your circuit as the below diagram.) |
||
Line 8: | Line 8: | ||
== Connect your circuit as the below diagram. == | == Connect your circuit as the below diagram. == | ||
− | [[File: | + | [[File:QQ图片20130716162130.jpg]] |
− | + | ||
− | + | ||
== Example code: == | == Example code: == |
Revision as of 08:22, 16 July 2013
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
}