Outils pour utilisateurs

Outils du site


de_mblock_a_arduino

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
de_mblock_a_arduino [2024/09/20 08:23] mistertde_mblock_a_arduino [2024/09/26 18:17] (Version actuelle) mistert
Ligne 8: Ligne 8:
  
 **Feu avec gestion piéton** **Feu avec gestion piéton**
 +
 +{{ https://wokwi.com/projects/409652519952763905 | Animation Wokwi }}
  
 {{https://www.tinkercad.com/things/gBydTi2hoNY-shiny-crift/editel?sharecode=tc4mVedVXJd9oO__L33PfsOS_REZVp4Z5-dfHhG76EU | Lien vers TinkerCad}} {{https://www.tinkercad.com/things/gBydTi2hoNY-shiny-crift/editel?sharecode=tc4mVedVXJd9oO__L33PfsOS_REZVp4Z5-dfHhG76EU | Lien vers TinkerCad}}
Ligne 16: Ligne 18:
 // C++ code // C++ code
 // //
 +#define BOUTON_PIETON 3
 +#define FEU_ROUGE 5
 +#define FEU_VERT 6
 +#define FEU_ORANGE 7
 +#define FEU_PIETON 8
 +
 int appel_pieton; int appel_pieton;
-int btn; 
  
 void eteindre_feux() { void eteindre_feux() {
-  digitalWrite(5, LOW); +  digitalWrite(FEU_ROUGE, LOW); 
-  digitalWrite(6, LOW); +  digitalWrite(FEU_VERT, LOW); 
-  digitalWrite(7, LOW); +  digitalWrite(FEU_ORANGE, LOW); 
-  digitalWrite(8, LOW);+  digitalWrite(FEU_PIETON, LOW);
 } }
 + 
 void gerer_pieton() { void gerer_pieton() {
-  btn = digitalRead(4); +  appel_pieton = 1;
-  if (btn == HIGH) { +
-    appel_pieton = 1; +
-  }+
 } }
 + 
 void gerer_feu(int pin, int temps_s) { void gerer_feu(int pin, int temps_s) {
   eteindre_feux();   eteindre_feux();
-  if (pin == and appel_pieton == 1) { +  if (pin == FEU_ROUGE and appel_pieton == 1) { 
-    digitalWrite(5, HIGH); +    digitalWrite(FEU_ROUGE, HIGH); 
-    digitalWrite(8, HIGH);+    digitalWrite(FEU_PIETON, HIGH);
     delay(2000);     delay(2000);
-    digitalWrite(8, LOW); +    digitalWrite(FEU_PIETON, LOW); 
     appel_pieton = 0;     appel_pieton = 0;
 +    temps_s -=2;
   } else {   } else {
      digitalWrite(pin, HIGH);      digitalWrite(pin, HIGH);
Ligne 46: Ligne 51:
   delay((temps_s * 1000));   delay((temps_s * 1000));
 } }
- + 
 void setup() { void setup() {
-  pinMode(4INPUT); +  pinMode(BOUTON_PIETONINPUT_PULLUP); 
-  pinMode(5, OUTPUT); +  attachInterrupt(digitalPinToInterrupt(BOUTON_PIETON), gerer_pieton, FALLING); 
-  pinMode(6, OUTPUT); +  pinMode(FEU_ROUGE, OUTPUT); 
-  pinMode(7, OUTPUT); +  pinMode(FEU_VERT, OUTPUT); 
-  pinMode(8, OUTPUT);+  pinMode(FEU_ORANGE, OUTPUT); 
 +  pinMode(FEU_PIETON, OUTPUT);
 } }
 + 
 void loop() { void loop() {
-  gerer_pieton(); +  gerer_feu(FEU_ROUGE, 5); 
-  gerer_feu(5, 5); +  gerer_feu(FEU_VERT, 5); 
-  gerer_feu(6, 5); +  gerer_feu(FEU_ORANGE, 1);
-  gerer_feu(7, 1);+
 } }
 </code> </code>
  
de_mblock_a_arduino.1726820636.txt.gz · Dernière modification : 2024/09/20 08:23 de mistert