Created
October 25, 2018 09:39
-
-
Save gregberger/bcd2db6c3695f6e3a61b50fe5679dfe3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int broches[] = {8,9,10,11,12}; | |
int bouton = 2; | |
int compteur = 0; | |
int etat_precedent = HIGH; | |
void setup() { | |
for(int i = 0; i < 5; i++){ | |
pinMode(broches[i], OUTPUT); | |
} | |
pinMode(bouton, INPUT_PULLUP); | |
} | |
void loop() { | |
// lire l'état du bouton | |
bool etat = digitalRead(bouton); | |
// comparer l'état actuel à l'état précédent | |
if(etat != etat_precedent){ | |
// tester si le bouton vient d'être appuyé | |
if(etat == LOW && etat_precedent == HIGH){ | |
// augmenter la valeur du compteur | |
compteur = compteur + 1; | |
if(compteur > 4){ | |
compteur = 0; | |
} | |
} | |
delay(50); | |
} | |
etat_precedent = etat; | |
for(int i = 0; i < 5; i++){ | |
if(i < compteur){ | |
digitalWrite(broche[i], HIGH); | |
}else{ | |
digitalWrite(broche[i], LOW); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment