-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsemaforoComBotao.cpp
More file actions
51 lines (43 loc) · 1.01 KB
/
semaforoComBotao.cpp
File metadata and controls
51 lines (43 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
int redPin = 10;
int yellowPin = 9;
int greenPin = 8;
int buttonPin = 7;
int estadoBotao;
int estadoSemaforo;
void setup() {
// put your setup code here, to run once:
pinMode(redPin,OUTPUT);
pinMode(yellowPin,OUTPUT);
pinMode(greenPin,OUTPUT);
pinMode(buttonPin,INPUT);
estadoSemaforo = 1;
}
void loop() {
// put your main code here, to run repeatedly:
estadoBotao = digitalRead(buttonPin);
if(estadoBotao == HIGH) {
estadoSemaforo = (estadoSemaforo % 3)+1;
delay(300);
}
if(estadoSemaforo == 1) {
digitalWrite(greenPin,HIGH);
digitalWrite(yellowPin,LOW);
digitalWrite(redPin,LOW);
//delay(3000);
//estadoSemaforo = 2;
}
if(estadoSemaforo == 2) {
digitalWrite(greenPin,LOW);
digitalWrite(yellowPin,HIGH);
digitalWrite(redPin,LOW);
//delay(1000);
//estadoSemaforo = 3;
}
if(estadoSemaforo == 3) {
digitalWrite(greenPin,LOW);
digitalWrite(yellowPin,LOW);
digitalWrite(redPin,HIGH);
//delay(4000);
//estadoSemaforo = 1;
}
}