Merge remote-tracking branch 'refs/remotes/thomasfredericks/master'

This commit is contained in:
Albert Phan
2017-01-07 14:03:20 -08:00
4 changed files with 82 additions and 0 deletions
+6
View File
@@ -38,6 +38,12 @@ void Bounce::attach(int pin) {
#endif
}
void Bounce::attach(int pin, int mode){
pinMode(pin, mode);
this->attach(pin);
}
void Bounce::interval(uint16_t interval_millis)
{
this->interval_millis = interval_millis;
+3
View File
@@ -47,6 +47,9 @@ class Bounce
// Attach to a pin (and also sets initial state)
void attach(int pin);
// Attach to a pin (and also sets initial state) and sets pin to mode (INPUT/INPUT_PULLUP/OUTPUT)
void attach(int pin, int mode);
// Sets the debounce interval
void interval(uint16_t interval_millis);
@@ -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 );
}
}
+9
View File
@@ -0,0 +1,9 @@
name=Bounce2
version=2.1
author=Thomas O Fredericks <tof@t-o-f.info> with contributions fromEric Lowry, Jim Schimpf and Tom Harkaway
maintainer=Thomas O Fredericks <tof@t-o-f.info>
sentence=Debouncing library for Arduino and Wiring.
paragraph=Deboucing switches and toggles is important.
category=Signal Input/Output
url=https://github.com/thomasfredericks/Bounce2
architectures=*