#107
Feu de circulation ESP32
Simulation d'un vrai feu de circulation avec 3 LED rouge-jaune-vert. Les temps sont proches de la logique du trafic réel : rouge long, jaune court, vert long. Exemple classique de contrôle séquentiel GPIO.
Simulation d'un vrai feu de circulation avec 3 LED rouge-jaune-vert. Les temps sont proches de la logique du trafic réel : rouge long, jaune court, vert long. Exemple classique de contrôle séquentiel GPIO.


1const int RED = 5;
2const int YELLOW = 18;
3const int GREEN = 19;
4
5void setup() {
6 pinMode(RED, OUTPUT);
7 pinMode(YELLOW, OUTPUT);
8 pinMode(GREEN, OUTPUT);
9}
10
11void loop() {
12 // Kırmızı / Red
13 digitalWrite(RED, HIGH);
14 digitalWrite(YELLOW, LOW);
15 digitalWrite(GREEN, LOW);
16 delay(3000);
17
18 // Kırmızı + Sarı / Red + Yellow
19 digitalWrite(YELLOW, HIGH);
20 delay(800);
21
22 // Yeşil / Green
23 digitalWrite(RED, LOW);
24 digitalWrite(YELLOW, LOW);
25 digitalWrite(GREEN, HIGH);
26 delay(3000);
27
28 // Sarı / Yellow
29 digitalWrite(GREEN, LOW);
30 digitalWrite(YELLOW, HIGH);
31 delay(800);
32 digitalWrite(YELLOW, LOW);
33}