Updated documentation
This commit is contained in:
@@ -1,48 +0,0 @@
|
||||
|
||||
/*
|
||||
DESCRIPTION
|
||||
====================
|
||||
Simple example of the Bounce library that switches the debug LED when a button is pressed.
|
||||
*/
|
||||
// Include the Bounce2 library found here :
|
||||
// https://github.com/thomasfredericks/Bounce2
|
||||
#include <Bounce2.h>
|
||||
|
||||
#define BUTTON_PIN 2
|
||||
#define LED_PIN 13
|
||||
|
||||
// Instantiate a Bounce object
|
||||
Bounce debouncer = Bounce();
|
||||
|
||||
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.interval(5); // interval in ms
|
||||
|
||||
//Setup the LED :
|
||||
pinMode(LED_PIN,OUTPUT);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Update the Bounce instance :
|
||||
debouncer.update();
|
||||
|
||||
// Get the updated value :
|
||||
int value = debouncer.read();
|
||||
|
||||
// Turn on or off the LED as determined by the state :
|
||||
if ( value == LOW ) {
|
||||
digitalWrite(LED_PIN, HIGH );
|
||||
}
|
||||
else {
|
||||
digitalWrite(LED_PIN, LOW );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
|
||||
/*
|
||||
DESCRIPTION
|
||||
====================
|
||||
Simple example of the Bounce library that switches a LED when
|
||||
a state change (from HIGH to LOW) is triggered (for example when a button is pressed).
|
||||
|
||||
Set BOUNCE_PIN to the pin attached to the input (a button for example).
|
||||
Set LED_PIN to the pin attached to a LED.
|
||||
|
||||
*/
|
||||
|
||||
// WE WILL attach() THE Bounce INSTANCE TO THE FOLLOWING PIN IN setup()
|
||||
#define BOUNCE_PIN 2
|
||||
|
||||
// DEFINE THE PIN FOR THE LED :
|
||||
// 1) SOME BOARDS HAVE A DEFAULT LED (LED_BUILTIN)
|
||||
#define LED_PIN LED_BUILTIN
|
||||
// 2) OTHERWISE SET YOUR OWN PIN
|
||||
// #define LED_PIN 13
|
||||
|
||||
// Include the Bounce2 library found here :
|
||||
// https://github.com/thomasfredericks/Bounce2
|
||||
#include <Bounce2.h>
|
||||
|
||||
|
||||
// INSTANTIATE A Bounce OBJECT
|
||||
Bounce bounce = Bounce();
|
||||
|
||||
// SET A VARIABLE TO STORE THE LED STATE
|
||||
bool ledState = LOW;
|
||||
|
||||
void setup() {
|
||||
|
||||
// BOUNCE SETUP
|
||||
|
||||
// SELECT ONE OF THE FOLLOWING :
|
||||
// 1) IF YOUR INPUT HAS AN INTERNAL PULL-UP
|
||||
// bounce.attach( BOUNCE_PIN , INPUT_PULLUP ); // USE INTERNAL PULL-UP
|
||||
// 2) IF YOUR INPUT USES AN EXTERNAL PULL-UP
|
||||
bounce.attach( BOUNCE_PIN, INPUT ); // USE EXTERNAL PULL-UP
|
||||
|
||||
// DEBOUNCE INTERVAL IN MILLISECONDS
|
||||
bounce.interval(5); // interval in ms
|
||||
|
||||
// LED SETUP
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
digitalWrite(LED_PIN, ledState);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Update the Bounce instance (YOU MUST DO THIS EVERY LOOP)
|
||||
bounce.update();
|
||||
|
||||
// <Bounce>.changed() RETURNS true IF THE STATE CHANGED (FROM HIGH TO LOW OR LOW TO HIGH)
|
||||
if ( bounce.changed() ) {
|
||||
// THE STATE OF THE INPUT CHANGED
|
||||
// GET THE STATE
|
||||
int deboucedInput = bounce.read();
|
||||
// IF THE CHANGED VALUE IS LOW
|
||||
if ( deboucedInput == LOW ) {
|
||||
ledState = !ledState; // SET ledState TO THE OPPOSITE OF ledState
|
||||
digitalWrite(LED_PIN,ledState); // WRITE THE NEW ledState
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
|
||||
/*
|
||||
DESCRIPTION
|
||||
====================
|
||||
Pressing a physical button switches a LED on or off.
|
||||
Simple example of the Button class from the Bounce library.
|
||||
The Button class matches an electrical state to a physical action
|
||||
with <Button>.setPressedState(LOW or HIGH).
|
||||
|
||||
Set BUTTON_PIN to the pin attached to the button.
|
||||
Set LED_PIN to the pin attached to a LED.
|
||||
|
||||
*/
|
||||
|
||||
// WE WILL attach() THE BUTTON TO THE FOLLOWING PIN IN setup()
|
||||
#define BUTTON_PIN 2
|
||||
|
||||
// DEFINE THE PIN FOR THE LED :
|
||||
// 1) SOME BOARDS HAVE A DEFAULT LED (LED_BUILTIN)
|
||||
//#define LED_PIN LED_BUILTIN
|
||||
// 2) OTHERWISE SET YOUR OWN PIN
|
||||
#define LED_PIN 13
|
||||
|
||||
// Include the Bounce2 library found here :
|
||||
// https://github.com/thomasfredericks/Bounce2
|
||||
#include <Bounce2.h>
|
||||
|
||||
// INSTANTIATE A Button OBJECT
|
||||
Button button = Button();
|
||||
|
||||
|
||||
|
||||
// SET A VARIABLE TO STORE THE LED STATE
|
||||
bool ledState = LOW;
|
||||
|
||||
void setup() {
|
||||
|
||||
// BUTTON SETUP
|
||||
|
||||
// SELECT ONE OF THE FOLLOWING :
|
||||
// 1) IF YOUR BUTTON HAS AN INTERNAL PULL-UP
|
||||
// button.attach( BUTTON_PIN , INPUT_PULLUP ); // USE INTERNAL PULL-UP
|
||||
// 2) IF YOUR BUTTON USES AN EXTERNAL PULL-UP
|
||||
button.attach( BUTTON_PIN, INPUT ); // USE EXTERNAL PULL-UP
|
||||
|
||||
// DEBOUNCE INTERVAL IN MILLISECONDS
|
||||
button.interval(5);
|
||||
|
||||
// INDICATE THAT THE LOW STATE CORRESPONDS TO PHYSICALLY PRESSING THE BUTTON
|
||||
button.setPressedState(LOW);
|
||||
|
||||
// LED SETUP
|
||||
pinMode(LED_PIN,OUTPUT);
|
||||
digitalWrite(LED_PIN,ledState);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// UPDATE THE BUTTON
|
||||
// YOU MUST CALL THIS EVERY LOOP
|
||||
button.update();
|
||||
|
||||
// <Button>.pressed() RETURNS true IF THE STATE CHANGED
|
||||
// AND THE CURRENT STATE MATCHES <Button>.setPressedState(<HIGH or LOW>);
|
||||
if ( button.pressed() ) {
|
||||
|
||||
// TOGGLE THE LED STATE :
|
||||
ledState = !ledState; // SET ledState TO THE OPPOSITE OF ledState
|
||||
digitalWrite(LED_PIN,ledState); // WRITE THE NEW ledState
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
|
||||
|
||||
|
||||
/*
|
||||
DESCRIPTION
|
||||
====================
|
||||
Simple example of the Button class from the Bounce library.
|
||||
The Button class matches an electrical state to a physical action.
|
||||
that switches the debug LED when
|
||||
either of 2 buttons are pressed.
|
||||
*/
|
||||
|
||||
// Include the Bounce2 library found here :
|
||||
// https://github.com/thomasfredericks/Bounce2
|
||||
#include <Bounce2.h>
|
||||
|
||||
#define BUTTON_PIN_A 2
|
||||
#define BUTTON_PIN_B 3
|
||||
|
||||
|
||||
#define LED_PIN LED_BUILTIN
|
||||
|
||||
// Instantiate a Button object
|
||||
Button buttonA = Button();
|
||||
|
||||
// Instantiate another Button object
|
||||
Button buttonB = Button();
|
||||
|
||||
void setup() {
|
||||
|
||||
// SETUP BUTTON A
|
||||
buttonA.attach( BUTTON_PIN_A , INPUT_PULLUP );
|
||||
buttonA.interval(5); // interval in ms
|
||||
buttonA.setPressedState(LOW); // INDICATE THAT THE LOW STATE CORRESPONDS TO PHYSICALLY PRESSING THE BUTTON
|
||||
|
||||
// SETUP BUTTON B
|
||||
buttonB.attach( BUTTON_PIN_B , INPUT_PULLUP );
|
||||
buttonB.interval(5); // interval in ms
|
||||
buttonB.setPressedState(LOW); // INDICATE THAT THE LOW STATE CORRESPONDS TO PHYSICALLY PRESSING THE BUTTON
|
||||
|
||||
|
||||
// SETUP LED
|
||||
pinMode(LED_PIN,OUTPUT);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// UPDATE THE BUTTONS
|
||||
buttonA.update();
|
||||
buttonB.update();
|
||||
|
||||
|
||||
// TOGGLE THE LED IF EITHER BUTTON IS PRESSED
|
||||
if ( buttonA.pressed() || buttonB.pressed() ) {
|
||||
digitalWrite(LED_PIN, !digitalRead(LED_PIN) );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user