ENIB 2023 : Chauffe qui peut ! : Différence entre versions
(→photo de l'équipe) |
(→Code) |
||
Ligne 13 : | Ligne 13 : | ||
==Code== | ==Code== | ||
<pre> | <pre> | ||
− | + | // the setup function runs once when you press reset or power the board | |
+ | const int led0=D0; | ||
+ | const int led2=D3; | ||
+ | const int led3=D4; | ||
+ | const int led_epreuve=D5; | ||
+ | const int haut=D6; | ||
+ | const int bas=D7; | ||
+ | const int reset=D2; | ||
+ | int x=1; | ||
+ | |||
+ | bool etape1=false; | ||
+ | bool etape2=false; | ||
+ | bool etape3=false; | ||
+ | |||
+ | |||
+ | int nbr_haut=0; | ||
+ | int nbr_bas=0; | ||
+ | int nbr_reset=0; | ||
+ | |||
+ | |||
+ | void setup() { | ||
+ | Serial.begin(9600); | ||
+ | |||
+ | pinMode(haut, INPUT); | ||
+ | pinMode(bas, INPUT); | ||
+ | pinMode(reset,INPUT); | ||
+ | pinMode(led0,OUTPUT); | ||
+ | pinMode(led2,OUTPUT); | ||
+ | pinMode(led3,OUTPUT); | ||
+ | pinMode(led_epreuve,OUTPUT); | ||
+ | |||
+ | } | ||
+ | |||
+ | void etape(int a) | ||
+ | { | ||
+ | |||
+ | if (a==1) | ||
+ | { | ||
+ | if (nbr_haut==8 && nbr_bas==2) | ||
+ | { | ||
+ | |||
+ | etape1=true; | ||
+ | digitalWrite(led0,HIGH); | ||
+ | nbr_haut=0; | ||
+ | nbr_bas=0; | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | digitalWrite(led0,LOW); | ||
+ | digitalWrite(led2,LOW); | ||
+ | digitalWrite(led3,LOW); | ||
+ | digitalWrite(led_epreuve,LOW); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | else if (a==2) | ||
+ | { | ||
+ | if (nbr_haut==3 && nbr_bas==7) | ||
+ | { | ||
+ | etape2=true; | ||
+ | digitalWrite(led2,HIGH); | ||
+ | nbr_haut=0; | ||
+ | nbr_bas=0; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | else if (a==3) | ||
+ | { | ||
+ | if (nbr_haut==2 && nbr_bas==3) | ||
+ | { | ||
+ | etape3=true; | ||
+ | digitalWrite(led3,HIGH); | ||
+ | delay(5000); | ||
+ | |||
+ | nbr_haut=0; | ||
+ | nbr_bas=0; | ||
+ | bool etape1=false; | ||
+ | bool etape2=false; | ||
+ | bool etape3=false; | ||
+ | |||
+ | } | ||
+ | else | ||
+ | { | ||
+ | |||
+ | unsigned long currentTime=millis(); | ||
+ | |||
+ | Serial.println(currentTime); | ||
+ | if (currentTime >(x*4000)) | ||
+ | { | ||
+ | digitalWrite(led_epreuve,HIGH); | ||
+ | |||
+ | if(currentTime>(x*8000)) | ||
+ | { | ||
+ | digitalWrite(led_epreuve,LOW); | ||
+ | if (currentTime>(x*10000)) | ||
+ | { | ||
+ | digitalWrite(led_epreuve,HIGH); | ||
+ | if(currentTime>(x*14000)) | ||
+ | { | ||
+ | digitalWrite(led_epreuve,LOW); | ||
+ | if (currentTime>(x*16000)) | ||
+ | { | ||
+ | digitalWrite(led_epreuve,HIGH); | ||
+ | if(currentTime>(x*18000)) | ||
+ | { | ||
+ | digitalWrite(led_epreuve,LOW); | ||
+ | if (currentTime>(x*20000)) | ||
+ | { | ||
+ | digitalWrite(led_epreuve,HIGH); | ||
+ | if(currentTime>(x*22000)) | ||
+ | { | ||
+ | digitalWrite(led_epreuve,LOW); | ||
+ | if (currentTime>(x*24000)) | ||
+ | { | ||
+ | digitalWrite(led_epreuve,HIGH); | ||
+ | if (currentTime>(x*28000)) | ||
+ | { | ||
+ | digitalWrite(led_epreuve,LOW); | ||
+ | if(currentTime>(x*40000)) | ||
+ | { | ||
+ | x+=100; | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | void loop() { | ||
+ | |||
+ | if (etape1==false && etape2==false && etape3==false ) | ||
+ | { | ||
+ | etape(1); | ||
+ | Serial.println(nbr_bas); | ||
+ | Serial.println(nbr_haut); | ||
+ | //Serial.println(nbr_reset); | ||
+ | |||
+ | |||
+ | } | ||
+ | else if (etape1==true && etape2==false && etape3==false ) | ||
+ | { | ||
+ | etape(2); | ||
+ | Serial.println(nbr_bas); | ||
+ | Serial.println(nbr_haut); | ||
+ | |||
+ | } | ||
+ | else if (etape1==true && etape2==true && etape3==false) | ||
+ | { | ||
+ | etape(3); | ||
+ | Serial.println(nbr_bas); | ||
+ | Serial.println(nbr_haut); | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | if(digitalRead(haut)==LOW) | ||
+ | { | ||
+ | nbr_haut+=1; | ||
+ | //Serial.println("jeanlouis"); | ||
+ | pinMode(haut,OUTPUT); | ||
+ | delay(500); | ||
+ | |||
+ | digitalWrite(haut,HIGH); | ||
+ | |||
+ | pinMode(haut,INPUT); | ||
+ | |||
+ | |||
+ | } | ||
+ | |||
+ | else if(digitalRead(bas)==LOW) | ||
+ | { | ||
+ | nbr_bas+=1; | ||
+ | //Serial.println("jeanlouis"); | ||
+ | pinMode(bas,OUTPUT); | ||
+ | delay(500); | ||
+ | |||
+ | digitalWrite(bas,HIGH); | ||
+ | |||
+ | pinMode(bas,INPUT); | ||
+ | } | ||
+ | |||
+ | else if(digitalRead(reset)==HIGH) | ||
+ | { | ||
+ | Serial.println(nbr_reset); | ||
+ | nbr_bas=0; | ||
+ | nbr_haut=0; | ||
+ | nbr_reset+=1; | ||
+ | |||
+ | pinMode(reset,OUTPUT); | ||
+ | delay(100); | ||
+ | |||
+ | digitalWrite(reset,LOW); | ||
+ | |||
+ | pinMode(reset,INPUT); | ||
+ | } | ||
+ | |||
+ | else if(nbr_reset>=50) | ||
+ | { | ||
+ | etape1=false; | ||
+ | etape2=false; | ||
+ | etape3=false; | ||
+ | nbr_haut=0; | ||
+ | nbr_bas=0; | ||
+ | nbr_reset=0; | ||
+ | pinMode(reset,OUTPUT); | ||
+ | delay(100); | ||
+ | digitalWrite(reset,LOW); | ||
+ | pinMode(reset,INPUT); | ||
+ | |||
+ | |||
+ | } | ||
+ | } | ||
+ | |||
</pre> | </pre> | ||
Version du 26 janvier 2023 à 15:43
photo de l'équipe
Que fait ce projet ?
Liste des composants
- composant 1
- composant 2
- ...
Code
// the setup function runs once when you press reset or power the board const int led0=D0; const int led2=D3; const int led3=D4; const int led_epreuve=D5; const int haut=D6; const int bas=D7; const int reset=D2; int x=1; bool etape1=false; bool etape2=false; bool etape3=false; int nbr_haut=0; int nbr_bas=0; int nbr_reset=0; void setup() { Serial.begin(9600); pinMode(haut, INPUT); pinMode(bas, INPUT); pinMode(reset,INPUT); pinMode(led0,OUTPUT); pinMode(led2,OUTPUT); pinMode(led3,OUTPUT); pinMode(led_epreuve,OUTPUT); } void etape(int a) { if (a==1) { if (nbr_haut==8 && nbr_bas==2) { etape1=true; digitalWrite(led0,HIGH); nbr_haut=0; nbr_bas=0; } else { digitalWrite(led0,LOW); digitalWrite(led2,LOW); digitalWrite(led3,LOW); digitalWrite(led_epreuve,LOW); } } else if (a==2) { if (nbr_haut==3 && nbr_bas==7) { etape2=true; digitalWrite(led2,HIGH); nbr_haut=0; nbr_bas=0; } } else if (a==3) { if (nbr_haut==2 && nbr_bas==3) { etape3=true; digitalWrite(led3,HIGH); delay(5000); nbr_haut=0; nbr_bas=0; bool etape1=false; bool etape2=false; bool etape3=false; } else { unsigned long currentTime=millis(); Serial.println(currentTime); if (currentTime >(x*4000)) { digitalWrite(led_epreuve,HIGH); if(currentTime>(x*8000)) { digitalWrite(led_epreuve,LOW); if (currentTime>(x*10000)) { digitalWrite(led_epreuve,HIGH); if(currentTime>(x*14000)) { digitalWrite(led_epreuve,LOW); if (currentTime>(x*16000)) { digitalWrite(led_epreuve,HIGH); if(currentTime>(x*18000)) { digitalWrite(led_epreuve,LOW); if (currentTime>(x*20000)) { digitalWrite(led_epreuve,HIGH); if(currentTime>(x*22000)) { digitalWrite(led_epreuve,LOW); if (currentTime>(x*24000)) { digitalWrite(led_epreuve,HIGH); if (currentTime>(x*28000)) { digitalWrite(led_epreuve,LOW); if(currentTime>(x*40000)) { x+=100; } } } } } } } } } } } } } } void loop() { if (etape1==false && etape2==false && etape3==false ) { etape(1); Serial.println(nbr_bas); Serial.println(nbr_haut); //Serial.println(nbr_reset); } else if (etape1==true && etape2==false && etape3==false ) { etape(2); Serial.println(nbr_bas); Serial.println(nbr_haut); } else if (etape1==true && etape2==true && etape3==false) { etape(3); Serial.println(nbr_bas); Serial.println(nbr_haut); } if(digitalRead(haut)==LOW) { nbr_haut+=1; //Serial.println("jeanlouis"); pinMode(haut,OUTPUT); delay(500); digitalWrite(haut,HIGH); pinMode(haut,INPUT); } else if(digitalRead(bas)==LOW) { nbr_bas+=1; //Serial.println("jeanlouis"); pinMode(bas,OUTPUT); delay(500); digitalWrite(bas,HIGH); pinMode(bas,INPUT); } else if(digitalRead(reset)==HIGH) { Serial.println(nbr_reset); nbr_bas=0; nbr_haut=0; nbr_reset+=1; pinMode(reset,OUTPUT); delay(100); digitalWrite(reset,LOW); pinMode(reset,INPUT); } else if(nbr_reset>=50) { etape1=false; etape2=false; etape3=false; nbr_haut=0; nbr_bas=0; nbr_reset=0; pinMode(reset,OUTPUT); delay(100); digitalWrite(reset,LOW); pinMode(reset,INPUT); } }