#include <OneButton.h>
const byte pinBbouton = 8;
const byte pinLled = 13;
OneButton bouton(pinBbouton);
unsigned long debut;
enum {LED_OFF, LED_ON} etat = LED_OFF;
void allumer() {
digitalWrite(pinLled, HIGH);
debut = millis();
etat = LED_ON;
}
void eteindre() {
digitalWrite(pinLled, LOW);
etat = LED_OFF;
}
bool tempsEcoule() {
return millis() - debut >= 1000ul;
}
void appui() {
if (etat == LED_OFF) allumer();
}
void setup() {
pinMode(pinLled, OUTPUT); // Initialise la broche 13 comme sortie
bouton.attachClick(appui);
}
void loop() {
switch (etat) {
case LED_OFF: bouton.tick(); break;
case LED_ON: if (tempsEcoule()) eteindre(); break;
}
}