Updating documentation
This commit is contained in:
@@ -4,6 +4,8 @@ Debouncing library for Arduino and Wiring by Thomas Ouellet Fredericks with cont
|
||||
|
||||
More about debouncing: http://en.wikipedia.org/wiki/Debounce#Contact_bounce
|
||||
|
||||
See the bottom of this page for a basic usage example and the "examples" folder for more.
|
||||
|
||||
## GITHUB PAGE
|
||||
|
||||
https://github.com/thomasfredericks/Bounce2
|
||||
@@ -23,7 +25,7 @@ Install through your software's Library Manager or download the latest version [
|
||||
The original version of Bounce (Bounce 1) is included in the download but not supported anymore.
|
||||
|
||||
|
||||
# DEBOUNCE ALGORITHMS
|
||||
# DEBOUNCE ALGORITHMS (FOR ADVANCED USERS)
|
||||
|
||||
|
||||
## STABLE INTERVAL
|
||||
@@ -52,4 +54,44 @@ By defining "#define BOUNCE_WITH_PROMPT_DETECTION" in "Bounce.h" (or in your cod
|
||||
|
||||
```
|
||||
#define BOUNCE_WITH_PROMPT_DETECTION
|
||||
```
|
||||
```
|
||||
|
||||
# BASIC EXAMPLE
|
||||
|
||||
```cpp
|
||||
// This example toggles the debug LED (pin 13) on or off
|
||||
// when a button on pin 2 is pressed.
|
||||
|
||||
// Include the Bounce2 library found here :
|
||||
// https://github.com/thomasfredericks/Bounce2
|
||||
#include <Bounce2.h>
|
||||
|
||||
#define BUTTON_PIN 2
|
||||
#define LED_PIN 13
|
||||
|
||||
int ledState = LOW;
|
||||
|
||||
|
||||
Bounce debouncer = Bounce(); // Instantiate a Bounce object
|
||||
|
||||
void setup() {
|
||||
|
||||
debouncer.attach(BUTTON_PIN,INPUT_PULLUP); // Attach the debouncer to a pin with INPUT_PULLUP mode
|
||||
debouncer.interval(500);
|
||||
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
+10
-21
@@ -1,48 +1,37 @@
|
||||
|
||||
// Detect the falling edge
|
||||
// This example toggles the debug LED (pin 13) on or off
|
||||
// when a button on pin 2 is pressed.
|
||||
|
||||
// Include the Bounce2 library found here :
|
||||
// https://github.com/thomasfredericks/Bounce2
|
||||
#include <Bounce2.h>
|
||||
|
||||
|
||||
#define BUTTON_PIN 2
|
||||
#define LED_PIN 13
|
||||
|
||||
int ledState = LOW;
|
||||
|
||||
|
||||
// Instantiate a Bounce object :
|
||||
Bounce debouncer = Bounce();
|
||||
Bounce debouncer = Bounce(); // Instantiate a Bounce object
|
||||
|
||||
void setup() {
|
||||
|
||||
// Setup the button with an internal pull-up :
|
||||
pinMode(BUTTON_PIN,INPUT_PULLUP);
|
||||
|
||||
// After setting up the button, setup the Bounce instance :
|
||||
debouncer.attach(BUTTON_PIN);
|
||||
debouncer.attach(BUTTON_PIN,INPUT_PULLUP); // Attach the debouncer to a pin with INPUT_PULLUP mode
|
||||
debouncer.interval(500);
|
||||
|
||||
// Setup the LED :
|
||||
pinMode(LED_PIN,OUTPUT);
|
||||
|
||||
pinMode(LED_PIN,OUTPUT); // Setup the LED
|
||||
digitalWrite(LED_PIN,ledState);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// Update the Bounce instance :
|
||||
debouncer.update();
|
||||
debouncer.update(); // Update the Bounce instance
|
||||
|
||||
// Call code if Bounce fell (transition from HIGH to LOW) :
|
||||
if ( debouncer.fell() ) {
|
||||
|
||||
// Toggle LED state :
|
||||
ledState = !ledState;
|
||||
digitalWrite(LED_PIN,ledState);
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user