-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeu_tp.ino
109 lines (92 loc) · 2.14 KB
/
feu_tp.ino
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const int VERT_1 = 2;
const int JAUNE_1 = 3;
const int ROUGE_1 = 4;
const int VERT_2 = 5;
const int JAUNE_2=6;
const int ROUGE_2 = 7;
void setup() {
Serial.begin(9600);
// put your setup code here, to run once:
pinMode(VERT_1, OUTPUT); pinMode(JAUNE_1, OUTPUT); pinMode(ROUGE_1, OUTPUT);
pinMode(VERT_2, OUTPUT); pinMode(JAUNE_2, OUTPUT); pinMode(ROUGE_2, OUTPUT);
}
int stateFeu1 = 0;
int stateFeu2 = 2;
// 0: vert
// 1: jaune
// 2: rouge
const int delayVert = 7000;
const int delayOrange = 3000;
long currentMillis = millis();
void loop() {
// put your main code here, to run repeatedly:
long now = millis();
if(stateFeu1==0){
if(now-currentMillis>=delayVert){
stateFeu1 = 1;
stateFeu2 = 0;
currentMillis = now;
}
}else if(stateFeu1==1){
if(now-currentMillis>=delayOrange){
stateFeu1 = 2;
stateFeu2 = 0;
currentMillis = now;
}
}else{
if(stateFeu2==0){
if(now-currentMillis>=delayVert){
stateFeu1 = 2;
stateFeu2 = 1;
currentMillis = now;
}
}else {
if(now-currentMillis>=delayOrange){
stateFeu1 = 0;
stateFeu2 = 2;
currentMillis = now;
}
}
}
Serial.println("restart ");
Serial.println(stateFeu2);
setState();
}
void setState(){
if(stateFeu1==0){
//mettre feu 2 au rouge || orange;
switchOn(VERT_1);
switchOn(ROUGE_2);
switchOff(JAUNE_1);
switchOff(ROUGE_1);
switchOff(VERT_2);
switchOff(JAUNE_2);
}else if(stateFeu1==1){
//mettre feu 2 au rouge;
switchOn(JAUNE_1);
switchOn(ROUGE_2);
switchOff(VERT_1);
switchOff(ROUGE_1);
switchOff(JAUNE_2);
switchOff(VERT_2);
}else if(stateFeu1==2){
//mettre feu 2 au vert;
if(stateFeu2==0){
switchOn(VERT_2);
switchOff(JAUNE_2);
}else{
switchOn(JAUNE_2);
switchOff(VERT_2);
}
switchOn(ROUGE_1);
switchOff(VERT_1);
switchOff(JAUNE_1);
switchOff(ROUGE_2);
}
}
void switchOff(int led){
digitalWrite(led, HIGH);
}
void switchOn(int led){
digitalWrite(led, LOW);
}