Created
September 8, 2018 02:57
-
-
Save j15e/176eac792af50487fae3a80783be0da2 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
const int GAUCHE = 11; | |
const int BARRE = 10; | |
const int DROITE = 9; | |
const int BOUTON = A0; | |
int val; | |
int oldVal; | |
int counter = 5; | |
int delay1 = 1250; | |
int lastToggle = 0; | |
bool displayOn = false; | |
void setup() { | |
pinMode(GAUCHE,OUTPUT); | |
pinMode(BARRE,OUTPUT); | |
pinMode(DROITE,OUTPUT); | |
pinMode(BOUTON,INPUT); | |
} | |
void loop() { | |
val = digitalRead(BOUTON); | |
if((val == LOW) && (oldVal == HIGH)) { | |
++counter; | |
} | |
oldVal = val; | |
delay(1); | |
switch(val) { | |
case 1: | |
flasher(HIGH, HIGH, LOW); | |
break; | |
case 2: | |
flasher(LOW, HIGH, LOW); | |
break; | |
case 3: | |
flasher(LOW, HIGH, HIGH); | |
break; | |
case 4: | |
flasher(HIGH, HIGH, HIGH); | |
break; | |
case 5: | |
counter = 1; | |
break; | |
} | |
} | |
void flasher(int gauche, int barre, int droite) { | |
// Si ça fait plus que delay1 qu'on a flashé, on remet les leds actif à nouveau | |
if(millis() > lastToggle + delay1) { | |
lastToggle = millis(); | |
displayOn = !displayOn; | |
} | |
if(displayOn) { | |
set_leds(gauche, barre, droite); | |
} else { | |
set_leds(LOW, LOW, LOW); | |
} | |
} | |
void set_leds(int gauche, int barre, int droite) { | |
digitalWrite(GAUCHE, gauche); | |
digitalWrite(BARRE, barre); | |
digitalWrite(DROITE, droite); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment