Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define PIN_BTN_1 5
- #define PIN_BTN_2 6
- #define PIN_BTN_3 7
- #define PIN_LED_VERTE 8
- #define PIN_LED_ROUGE 9
- #define TIME_ANTIREBOND 250
- unsigned long timeBtn1 = 0;
- unsigned long timeBtn2 = 0;
- unsigned long timeBtn3 = 0;
- int btn1Pressed = 0;
- int btn2Pressed = 0;
- int btn3Pressed = 0;
- void setup(){
- pinMode(PIN_BTN_1, INPUT_PULLUP);
- pinMode(PIN_BTN_2, INPUT_PULLUP);
- pinMode(PIN_BTN_3, INPUT_PULLUP);
- pinMode(PIN_LED_VERTE, OUTPUT);
- pinMode(PIN_LED_ROUGE, OUTPUT);
- }
- void loop(){
- if( ((millis() - timeBtn1) >= TIME_ANTIREBOND) & !btn1Pressed & !digitalRead(PIN_BTN_1) ){
- timeBtn1 = millis();
- btn1Pressed = 1;
- }
- else if( ((millis() - timeBtn2) >= TIME_ANTIREBOND) & !btn2Pressed & !digitalRead(PIN_BTN_2) & btn1Pressed ){
- timeBtn2=millis();
- digitalWrite(PIN_LED_VERTE, HIGH);
- //tu peux aussi mettre en bascule on et off
- //digitalWrite(PIN_LED_VERTE, !digitalRead(PIN_LED_VERTE));
- //on reinitialise
- btn1Pressed = 0;
- btn2Pressed = 0;
- }
- else if( ((millis() - timeBtn3) >= TIME_ANTIREBOND) & !btn2Pressed & !digitalRead(PIN_BTN_2) & btn1Pressed ){
- timeBtn3=millis();
- digitalWrite(PIN_LED_ROUGE, HIGH);
- //tu peux aussi mettre en bascule on et off
- //digitalWrite(PIN_LED_ROUGE, !digitalRead(PIN_LED_ROUGE));
- //on reinitialise
- btn1Pressed = 0;
- btn3Pressed = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment