From 6c6607272f9b5d5aca22d487b064d2acf5ddf4a0 Mon Sep 17 00:00:00 2001 From: NoobTracker <63962365+NoobTracker@users.noreply.github.com> Date: Fri, 24 Apr 2020 19:50:50 +0200 Subject: [PATCH] Example for setInvert() --- examples/changeInvert/changeInvert.ino | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 examples/changeInvert/changeInvert.ino diff --git a/examples/changeInvert/changeInvert.ino b/examples/changeInvert/changeInvert.ino new file mode 100644 index 0000000..bd51413 --- /dev/null +++ b/examples/changeInvert/changeInvert.ino @@ -0,0 +1,35 @@ +// This example toggles the debug LED (pin 13) on or off +// when a button on pin 2 is released. It uses the setInvert() function. + +// Include the Bounce2 library found here : +// https://github.com/thomasfredericks/Bounce2 +#include + +#define BUTTON_PIN 2 +#define LED_PIN 13 + +int ledState = LOW; + + +Bounce debouncer = Bounce(); // Instantiate a Bounce object + +void setup() { + + debouncer.setInvert(true); + debouncer.attach(BUTTON_PIN,INPUT_PULLUP); // Attach the debouncer to a pin with INPUT_PULLUP mode + debouncer.interval(1); // Use a debounce interval of 25 milliseconds + + pinMode(LED_PIN,OUTPUT); // Setup the LED + digitalWrite(LED_PIN,ledState); + +} + +void loop() { + + debouncer.update(); // Update the Bounce instance + + if ( debouncer.fell() ) { // Call code if button transitions from HIGH to LOW + ledState = !ledState; // Toggle LED state + digitalWrite(LED_PIN,ledState); // Apply new LED state + } +}