25/06/2015
DFRduino Beginner Kit For Arduino V3 SKU:DFR0100 Robot Wiki
http://www.dfrobot.com/wiki/index.php/DFRduino_Beginner_Kit_For_Arduino_V3_SKU:DFR0100
5/23
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
pinMode(carYellow, OUTPUT);
pinMode(carGreen, OUTPUT);
pinMode(pedRed, OUTPUT);
pinMode(pedGreen, OUTPUT);
pinMode(button, INPUT);
digitalWrite(carGreen, HIGH); //turn on the green lights
digitalWrite(pedRed, HIGH);
}
void
loop() {
int
state = digitalRead(button);
//check if button is pressed and it is over 5 seconds since last button press
if(state == HIGH && (millis() ‐ changeTime)> 5000){
//call the function to change the lights
changeLights();
}
}
void
changeLights() {
digitalWrite(carGreen, LOW); //green off
digitalWrite(carYellow, HIGH); //yellow on
delay(2000); //wait 2 seconds
digitalWrite(carYellow, LOW); //yellow off
digitalWrite(carRed, HIGH); //red on
delay(1000); //wait 1 second till its safe
digitalWrite(pedRed, LOW); //ped red off
digitalWrite(pedGreen, HIGH); //ped green on
delay(crossTime); //wait for preset time period
//flash the ped green
for
(int
x=0; x<10; x++) {
digitalWrite(pedGreen, HIGH);
delay(250);
digitalWrite(pedGreen, LOW);
delay(250);
}
digitalWrite(pedRed, HIGH);//turn ped red on
delay(500);
digitalWrite(carRed, LOW); //red off
digitalWrite(carYellow, HIGH); //yellow on