Initial commit
This is just the 2018 code configured for PlatformIO
This commit is contained in:
48
lib/Bounce2/examples/bounce/bounce.ino
Normal file
48
lib/Bounce2/examples/bounce/bounce.ino
Normal file
@ -0,0 +1,48 @@
|
||||
|
||||
/*
|
||||
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 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
64
lib/Bounce2/examples/bounce2buttons/bounce2buttons.ino
Normal file
64
lib/Bounce2/examples/bounce2buttons/bounce2buttons.ino
Normal file
@ -0,0 +1,64 @@
|
||||
|
||||
/*
|
||||
DESCRIPTION
|
||||
====================
|
||||
Simple example of the Bounce library 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_1 2
|
||||
#define BUTTON_PIN_2 3
|
||||
|
||||
|
||||
#define LED_PIN 13
|
||||
|
||||
// Instantiate a Bounce object
|
||||
Bounce debouncer1 = Bounce();
|
||||
|
||||
// Instantiate another Bounce object
|
||||
Bounce debouncer2 = Bounce();
|
||||
|
||||
void setup() {
|
||||
|
||||
// Setup the first button with an internal pull-up :
|
||||
pinMode(BUTTON_PIN_1,INPUT_PULLUP);
|
||||
// After setting up the button, setup the Bounce instance :
|
||||
debouncer1.attach(BUTTON_PIN_1);
|
||||
debouncer1.interval(5); // interval in ms
|
||||
|
||||
// Setup the second button with an internal pull-up :
|
||||
pinMode(BUTTON_PIN_2,INPUT_PULLUP);
|
||||
// After setting up the button, setup the Bounce instance :
|
||||
debouncer2.attach(BUTTON_PIN_2);
|
||||
debouncer2.interval(5); // interval in ms
|
||||
|
||||
|
||||
//Setup the LED :
|
||||
pinMode(LED_PIN,OUTPUT);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Update the Bounce instances :
|
||||
debouncer1.update();
|
||||
debouncer2.update();
|
||||
|
||||
// Get the updated value :
|
||||
int value1 = debouncer1.read();
|
||||
int value2 = debouncer2.read();
|
||||
|
||||
// Turn on the LED if either button is pressed :
|
||||
if ( value1 == LOW || value2 == LOW ) {
|
||||
digitalWrite(LED_PIN, HIGH );
|
||||
}
|
||||
else {
|
||||
digitalWrite(LED_PIN, LOW );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
56
lib/Bounce2/examples/bounce_multiple/bounce_multiple.ino
Normal file
56
lib/Bounce2/examples/bounce_multiple/bounce_multiple.ino
Normal file
@ -0,0 +1,56 @@
|
||||
// Detect the falling edge of multiple buttons.
|
||||
// Eight buttons with internal pullups.
|
||||
// Toggles a LED when any button is pressed.
|
||||
// Buttons on pins 2,3,4,5,6,7,8,9
|
||||
|
||||
// Include the Bounce2 library found here :
|
||||
// https://github.com/thomasfredericks/Bounce2
|
||||
#include <Bounce2.h>
|
||||
|
||||
#define LED_PIN 13
|
||||
|
||||
#define NUM_BUTTONS 8
|
||||
const uint8_t BUTTON_PINS[NUM_BUTTONS] = {2, 3, 4, 5, 6, 7, 8, 9};
|
||||
|
||||
int ledState = LOW;
|
||||
|
||||
Bounce * buttons = new Bounce[NUM_BUTTONS];
|
||||
|
||||
void setup() {
|
||||
|
||||
for (int i = 0; i < NUM_BUTTONS; i++) {
|
||||
buttons[i].attach( BUTTON_PINS[i] , INPUT_PULLUP ); //setup the bounce instance for the current button
|
||||
buttons[i].interval(25); // interval in ms
|
||||
}
|
||||
|
||||
// Setup the LED :
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
digitalWrite(LED_PIN, ledState);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
bool needToToggleLed = false;
|
||||
|
||||
|
||||
for (int i = 0; i < NUM_BUTTONS; i++) {
|
||||
// Update the Bounce instance :
|
||||
buttons[i].update();
|
||||
// If it fell, flag the need to toggle the LED
|
||||
if ( buttons[i].fell() ) {
|
||||
needToToggleLed = true;
|
||||
}
|
||||
}
|
||||
|
||||
// if a LED toggle has been flagged :
|
||||
if ( needToToggleLed ) {
|
||||
// Toggle LED state :
|
||||
ledState = !ledState;
|
||||
digitalWrite(LED_PIN, ledState);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
48
lib/Bounce2/examples/change/change.ino
Normal file
48
lib/Bounce2/examples/change/change.ino
Normal file
@ -0,0 +1,48 @@
|
||||
|
||||
// Detect the falling edge
|
||||
|
||||
// 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();
|
||||
|
||||
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(500);
|
||||
|
||||
// Setup the LED :
|
||||
pinMode(LED_PIN,OUTPUT);
|
||||
digitalWrite(LED_PIN,ledState);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// Update the Bounce instance :
|
||||
debouncer.update();
|
||||
|
||||
// Call code if Bounce fell (transition from HIGH to LOW) :
|
||||
if ( debouncer.fell() ) {
|
||||
|
||||
// Toggle LED state :
|
||||
ledState = !ledState;
|
||||
digitalWrite(LED_PIN,ledState);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 47 KiB |
53
lib/Bounce2/examples/duration/duration.ino
Normal file
53
lib/Bounce2/examples/duration/duration.ino
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
DESCRIPTION
|
||||
====================
|
||||
Reports through serial (57600 baud) the time since
|
||||
a button press (transition from HIGH to LOW).
|
||||
|
||||
*/
|
||||
|
||||
// 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();
|
||||
|
||||
unsigned long buttonPressTimeStamp;
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(57600);
|
||||
|
||||
// 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);
|
||||
|
||||
// Setup the LED :
|
||||
pinMode(LED_PIN,OUTPUT);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// Update the Bounce instance :
|
||||
debouncer.update();
|
||||
|
||||
// Call code if Bounce fell (transition from HIGH to LOW) :
|
||||
if ( debouncer.fell() ) {;
|
||||
|
||||
Serial.println( millis()-buttonPressTimeStamp );
|
||||
buttonPressTimeStamp = millis();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
86
lib/Bounce2/examples/retrigger/retrigger.ino
Normal file
86
lib/Bounce2/examples/retrigger/retrigger.ino
Normal file
@ -0,0 +1,86 @@
|
||||
|
||||
/*
|
||||
DESCRIPTION
|
||||
====================
|
||||
Example of the bounce library that shows how to retrigger an event when a button is held down.
|
||||
In this case, the debug LED will blink every 500 ms as long as the button is held down.
|
||||
Open the Serial Monitor (57600 baud) for debug messages.
|
||||
|
||||
*/
|
||||
|
||||
// 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();
|
||||
|
||||
int buttonState;
|
||||
unsigned long buttonPressTimeStamp;
|
||||
|
||||
int ledState;
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(57600);
|
||||
|
||||
// Setup the button
|
||||
pinMode(BUTTON_PIN,INPUT);
|
||||
// Activate internal pull-up
|
||||
digitalWrite(BUTTON_PIN,HIGH);
|
||||
|
||||
// After setting up the button, setup debouncer
|
||||
debouncer.attach(BUTTON_PIN);
|
||||
debouncer.interval(5);
|
||||
|
||||
//Setup the LED
|
||||
pinMode(LED_PIN,OUTPUT);
|
||||
digitalWrite(LED_PIN,ledState);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Update the debouncer and get the changed state
|
||||
boolean changed = debouncer.update();
|
||||
|
||||
|
||||
|
||||
if ( changed ) {
|
||||
// Get the update value
|
||||
int value = debouncer.read();
|
||||
if ( value == HIGH) {
|
||||
ledState = LOW;
|
||||
digitalWrite(LED_PIN, ledState );
|
||||
|
||||
buttonState = 0;
|
||||
Serial.println("Button released (state 0)");
|
||||
|
||||
} else {
|
||||
ledState = HIGH;
|
||||
digitalWrite(LED_PIN, ledState );
|
||||
|
||||
buttonState = 1;
|
||||
Serial.println("Button pressed (state 1)");
|
||||
buttonPressTimeStamp = millis();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ( buttonState == 1 ) {
|
||||
if ( millis() - buttonPressTimeStamp >= 500 ) {
|
||||
buttonPressTimeStamp = millis();
|
||||
if ( ledState == HIGH ) ledState = LOW;
|
||||
else if ( ledState == LOW ) ledState = HIGH;
|
||||
digitalWrite(LED_PIN, ledState );
|
||||
Serial.println("Retriggering button");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user