#include <OneButton.h>
const byte buttonPin = 3; // switch
const unsigned long seuilTemps = 3000; // seuil de temps d'appui long
OneButton bouton(buttonPin); // set the INPUT_PULLUP
// dans cette fonction, donc le clique simple, on demarre le moteur
void simpleClick() {
Serial.println("SIMPLE CLICK");
}
// dans cette fonction, donc le click long, on arrete le moteur et on active le mode sleep
void clickLong() {
Serial.println("LONG CLICK");
}
void setup() {
Serial.begin(115200);
bouton.setPressMs(seuilTemps); // temps d'appui long
bouton.attachClick(simpleClick); // fonction appelée en cas d'appui court pour lancer le moteur
bouton.attachLongPressStop(clickLong); // fonction appelée en cas d'appui long pour le mode veille
Serial.println("program start!");
}
void loop() {
bouton.tick(); // keep watching the push button
}