diff --git a/README.md b/README.md index 93eb4a3..e69acba 100644 --- a/README.md +++ b/README.md @@ -33,15 +33,15 @@ Bounce2::Button button = Bounce2::Button(); // INSTANTIATE A Bounce2::Button OBJ ## CONFIGURE IN SETUP() In the code sample below : -* Change to the hardware pin of the button. -* Change to INPUT_PULLUP if using an internal pullup, or INPUT if using an external pullup. -* Change to the debounce interval in millisecons. 5 is a good value. -* Change to LOW if the button outputs a LOW when pressed, or to HIGH of the button outputs a HIGH when pressed. +* Change *PIN* to the hardware pin of the button. +* Change *PIN_MODE* to `INPUT_PULLUP` if using an internal pullup, or `INPUT` if using an external pullup. +* Change *INTERVAL_IN_MS* to the debounce interval in millisecons. `5` is a good value. +* Change *PRESSED_STATE* to `LOW` if the button outputs a `LOW` when pressed, or to `HIGH` if the button outputs a `HIGH` when pressed. ```cpp -button.attach ( , ); -button.interval( ); -button.setPressedState( ); +button.attach ( PIN , PIN_MODE ); +button.interval( INTERVAL_IN_MS ); +button.setPressedState( PRESSED_STATE ); ``` diff --git a/examples/more/bounce_m5stack_atom_key-unit/bounce_m5stack_atom_key-unit.ino b/examples/more/bounce_m5stack_atom_key-unit/bounce_m5stack_atom_key-unit.ino new file mode 100644 index 0000000..5c90fef --- /dev/null +++ b/examples/more/bounce_m5stack_atom_key-unit/bounce_m5stack_atom_key-unit.ino @@ -0,0 +1,67 @@ +// Le code de base pour le M5Stack Atom + +// Inclure la librairie M5 (version pour M5Atom) : +// https://github.com/m5stack/M5Atom +#include + +// Inclure la librairie FastLED qui va gérer le pixel : +// https://github.com/FastLED/FastLED +#include + +// Un tableau qui contient une variable de type CRGB. +// Il y a un seul pixel, mais il doit être dans un tableau. +// CRGB est un type de couleur défini par la lirairie FastLed : +// https://github.com/FastLED/FastLED/wiki/Pixel-reference#crgb-reference +CRGB mesPixels[1]; + +#include +Bounce2::Button button = Bounce2::Button(); // INSTANTIATE A Bounce2::Button OBJECT + +bool ledToggle = false; + +void setup() { + // Démarrer la libraire M5 avec toutes les options de pré-configuration désactivées : + M5.begin(false, false, false); + + // Démarrer la connexion sérielle : + Serial.begin(115200); + + // Ajouter le pixel (il y en a un seul) du M5Atom à la librairie FastLED : + FastLED.addLeds(mesPixels, 1); + + // Animation de démarrage + while (millis() < 5000) { + mesPixels[0] = CHSV((millis() / 5) % 255, 255, 255 - (millis() * 255 / 5000)); + FastLED.show(); + delay(50); + } + mesPixels[0] = CRGB(0, 0, 0); + FastLED.show(); + + button.attach(32, INPUT_PULLUP); + button.interval(5); + button.setPressedState(LOW); +} + +void loop() { + // Toujours inclure M5.update() au début de loop() : + M5.update(); + + // UPDATE THE BUTTON BY CALLING .update() AT THE BEGINNING OF THE LOOP: + button.update(); + + // IF THE BUTTON WAS PRESSED THIS LOOP: + if (button.pressed()) { + // DO SOMETHING IF THE BUTTON WAS PRESSED THIS LOOP... + + if ( ledToggle ) { + ledToggle = false; + mesPixels[0] = CRGB(0, 0, 0); + } else { + ledToggle = true; + mesPixels[0] = CRGB(255,255,255); + } + + FastLED.show(); + } +} \ No newline at end of file