diff --git a/README.md b/README.md index 34854c9..bc0a734 100755 --- a/README.md +++ b/README.md @@ -26,12 +26,13 @@ This library enables you to create non-blocking timers using simple, common sens * [Return Values on Stopped Timers](#return-values-on-stopped-timers) * [Summary](#summary) * [Examples](#examples) - * [BlockNotBlink](#blocknotblink) - * [BlockNotBlinkParty](#blocknotblinkparty) - * [DurationTrigger](#durationtrigger) - * [OnWithOffTimers](#onwithofftimers) - * [ResetAll](#resetall) - * [TimersRules](#timersrules) + * [BlockNot Blink](#blocknotblink) + * [BlockNot Blink Party](#blocknotblinkparty) + * [Button Debounce](#buttondebounce) + * [Duration Trigger](#durationtrigger) + * [On With Off Timers](#onwithofftimers) + * [Reset All](#resetall) + * [Timer's Rules](#timersrules) * [Library](#library) * [Methods](#methods) * [Macros](#macros) @@ -510,7 +511,7 @@ There are more methods that allow you to affect change on your timers after inst # Examples -There are currently seven examples in the library. +There are currently eight examples in the library. ### BlockNotBlink @@ -522,6 +523,10 @@ If you have a nano or an uno or equivalent laying around and four LEDs and some **Non-Blocking MATTERS!** +### ButtonDebounce + +Learn how to debounce a button without using delay() + ### DurationTrigger Read the section above to get an idea of what TRIGGERED_ON_DURATION does, then load this example up and play around @@ -557,6 +562,8 @@ stopAfterThreeTimer. When you look at the number of milliseconds in each of the outputs, you can see that indeed it does trigger three seconds after being reset, but then it does not re-trigger until after it is reset again. + + - Thanks to [@SteveRMann](https://github.com/SteveRMann) for kick-starting this example and working with me on fine-tuning it. ### MillisRolloverTest diff --git a/examples/ButtonDebounce/ButtonDebounce.ino b/examples/ButtonDebounce/ButtonDebounce.ino new file mode 100644 index 0000000..809a9ad --- /dev/null +++ b/examples/ButtonDebounce/ButtonDebounce.ino @@ -0,0 +1,38 @@ +#include + + /** + * BlockNot can be used to debounce a button, and you don't even have to be conservative on your delay time + * because when you press a button, the odds that you'll press a button again within a single second even + * is really low, and since timers trigger AFTER the stated duration has passed, you can have your button + * code run only if the timer has triggered, which means that if it has triggered your code will run immediately + * without needing to debounce it using the delay() method, and after you let go of the button, the timer will + * be primed and ready to go very shortly there after. So then the duration of the timer can be as long as + * half a second or even a full second or longer since the timer is primed after that duration has already + * passed. You're basically debouncing ahead of time so that your button code can run immediately. + * + * Connect one pin of your button to pin 12 of your Arduino, then the other button pin goes to ground, then + * upload this sketch and try it out. + * + * If you want the button to respond faster than one second, change the timers duration from 1, SECONDS to + * something smaller like just 500 for half a second or 250 for 1/4 second. + */ + +BlockNot buttonTimer(1, SECONDS); +//BlockNot buttonTimer(500); // 1/2 second +//BlockNot buttonTimer(250); // 1/4 second + +#define BUTTON 12 + +#define BUTTON_PRESSED digitalRead(BUTTON) == LOW; + + + void setup() { + Serial.begin(115200); + pinMode(BUTTON, INPUT_PULLUP); + } + + loop() { + if(BUTTON_PRESSED) + if(buttonTimer.TRIGGERED) + Serial.println("Button Pressed!"); + } \ No newline at end of file diff --git a/library.properties b/library.properties index 66a39b5..5917890 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=BlockNot -version=2.0.3 +version=2.0.4 author=Michael Sims maintainer=Michael Sims sentence=BlockNot gives you non-blocking timers with simplicity.