Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
804c4c06d2 | ||
|
|
f362cf32e7 | ||
|
|
1badf95e3b | ||
|
|
ed79ad5b79 | ||
|
|
91fea0682d | ||
|
|
e1c506bb48 | ||
|
|
e68f6110ee | ||
|
|
371e2cff35 | ||
|
|
9276539335 | ||
|
|
cda0200633 | ||
|
|
ff821cb300 | ||
|
|
b7cd534fb7 | ||
|
|
699b0e429c | ||
|
|
71568702f2 | ||
|
|
d2c9f1673c | ||
|
|
ee74d73978 | ||
|
|
d744e0690f | ||
|
|
152a64231a | ||
|
|
79db9f0016 | ||
|
|
5e100280c5 | ||
|
|
2ba0be8f83 | ||
|
|
28afcafa6a | ||
|
|
1645b897c8 | ||
|
|
68dc6f7830 | ||
|
|
f87ba5ba9f | ||
|
|
246096ae96 | ||
|
|
1ce882f949 | ||
|
|
a132f4ab43 | ||
|
|
e89801c2dd | ||
|
|
744a957b76 | ||
|
|
cd87a100be | ||
|
|
6f244834a4 | ||
|
|
5a481c6922 | ||
|
|
4207a8dd17 | ||
|
|
eb5ab9fad8 | ||
|
|
c445bbc7a7 | ||
|
|
c012c6c042 | ||
|
|
83bc18e245 | ||
|
|
3a88a924f2 | ||
|
|
fd99238112 | ||
|
|
9babb4fc38 | ||
|
|
878f86bf1c | ||
|
|
59d3c66c56 | ||
|
|
08392e0f01 | ||
|
|
3ddefb4ba4 | ||
|
|
172e3e0835 | ||
|
|
f51b22b708 | ||
|
|
1a6552ffe5 | ||
|
|
2b6be81dc1 | ||
|
|
6147a34058 | ||
|
|
1af864b0bd | ||
|
|
cf32eda85e | ||
|
|
a57ba4c66a | ||
|
|
85d80fe400 | ||
|
|
14f9c5c4a6 | ||
|
|
9335056c46 | ||
|
|
26e216c98d | ||
|
|
6228e09451 | ||
|
|
51032991ac | ||
|
|
de69c15225 | ||
|
|
220a287467 | ||
|
|
01e6fc9398 | ||
|
|
3e4738b4ef | ||
|
|
3706e16e4b | ||
|
|
9a275c4f96 | ||
|
|
d422d7c054 | ||
|
|
d3ef0365eb | ||
|
|
f5203d0fb8 | ||
|
|
c2e3cd5a2d | ||
|
|
32c1c48b26 | ||
|
|
5a132024fc | ||
|
|
cbe0b980b7 | ||
|
|
a1c83e9d7d | ||
|
|
f19d27689f | ||
|
|
045183b598 | ||
|
|
2ba409cd4a | ||
|
|
47d7fab6ac | ||
|
|
d0443e3f3d | ||
|
|
0f5acfd2c4 | ||
|
|
cbb12331c9 | ||
|
|
2c83e7f19c | ||
|
|
a5ee5f9e79 | ||
|
|
9d91d62d1e | ||
|
|
c0be1e178a | ||
|
|
742dfe9668 | ||
|
|
527524112d | ||
|
|
99e9334994 | ||
|
|
01a2a947ed | ||
|
|
8d5b3756b0 | ||
|
|
b061fcf83e | ||
|
|
7091ec8bf9 | ||
|
|
149abc4921 | ||
|
|
716c423922 | ||
|
|
9901bf1f23 | ||
|
|
80d29125d6 | ||
|
|
3f9594d49c | ||
|
|
5a53e1b757 | ||
|
|
391f7aaf7f | ||
|
|
06beac6d75 | ||
|
|
43b373c836 | ||
|
|
eea5da2ba2 | ||
|
|
2d586f5b50 | ||
|
|
8b60f9f057 | ||
|
|
ed75053c9e | ||
|
|
60edc5701e | ||
|
|
ffe7633042 | ||
|
|
c6d1aeb7eb | ||
|
|
0a30a709f0 | ||
|
|
3aaca27601 | ||
|
|
0016920498 | ||
|
|
f7f48e1760 | ||
|
|
56c943c894 | ||
|
|
bba2a0aa75 | ||
|
|
2d6327e91c | ||
|
|
50b796ccfc | ||
|
|
ea7731102f | ||
|
|
7ed666b7b1 | ||
|
|
a2ec7acd6c | ||
|
|
987d751bfa |
@@ -0,0 +1,51 @@
|
||||
# Sample workflow for building and deploying a Jekyll site to GitHub Pages
|
||||
name: Deploy Jekyll with GitHub Pages dependencies preinstalled
|
||||
|
||||
on:
|
||||
# Runs on pushes targeting the default branch
|
||||
push:
|
||||
branches: ["master"]
|
||||
|
||||
# Allows you to run this workflow manually from the Actions tab
|
||||
workflow_dispatch:
|
||||
|
||||
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
|
||||
permissions:
|
||||
contents: read
|
||||
pages: write
|
||||
id-token: write
|
||||
|
||||
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
|
||||
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
|
||||
concurrency:
|
||||
group: "pages"
|
||||
cancel-in-progress: false
|
||||
|
||||
jobs:
|
||||
# Build job
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup Pages
|
||||
uses: actions/configure-pages@v4
|
||||
- name: Build with Jekyll
|
||||
uses: actions/jekyll-build-pages@v1
|
||||
with:
|
||||
source: ./
|
||||
destination: ./_site
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-pages-artifact@v3
|
||||
|
||||
# Deployment job
|
||||
deploy:
|
||||
environment:
|
||||
name: github-pages
|
||||
url: ${{ steps.deployment.outputs.page_url }}
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
steps:
|
||||
- name: Deploy to GitHub Pages
|
||||
id: deployment
|
||||
uses: actions/deploy-pages@v4
|
||||
@@ -0,0 +1,2 @@
|
||||
*.db
|
||||
*.yml
|
||||
@@ -1,88 +0,0 @@
|
||||
|
||||
// Please read Bounce.h for information about the liscence and authors
|
||||
|
||||
#include "WProgram.h"
|
||||
#include "Bounce.h"
|
||||
|
||||
|
||||
Bounce::Bounce(uint8_t pin,unsigned long interval_millis)
|
||||
{
|
||||
interval(interval_millis);
|
||||
previous_millis = millis();
|
||||
state = digitalRead(pin);
|
||||
this->pin = pin;
|
||||
}
|
||||
|
||||
|
||||
void Bounce::write(int new_state)
|
||||
{
|
||||
this->state = new_state;
|
||||
digitalWrite(pin,state);
|
||||
}
|
||||
|
||||
|
||||
void Bounce::interval(unsigned long interval_millis)
|
||||
{
|
||||
this->interval_millis = interval_millis;
|
||||
this->rebounce_millis = 0;
|
||||
}
|
||||
|
||||
void Bounce::rebounce(unsigned long interval)
|
||||
{
|
||||
this->rebounce_millis = interval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int Bounce::update()
|
||||
{
|
||||
if ( debounce() ) {
|
||||
rebounce(0);
|
||||
return stateChanged = 1;
|
||||
}
|
||||
|
||||
// We need to rebounce, so simulate a state change
|
||||
|
||||
if ( rebounce_millis && (millis() - previous_millis >= rebounce_millis) ) {
|
||||
previous_millis = millis();
|
||||
rebounce(0);
|
||||
return stateChanged = 1;
|
||||
}
|
||||
|
||||
return stateChanged = 0;
|
||||
}
|
||||
|
||||
|
||||
unsigned long Bounce::duration()
|
||||
{
|
||||
return millis() - previous_millis;
|
||||
}
|
||||
|
||||
|
||||
int Bounce::read()
|
||||
{
|
||||
return (int)state;
|
||||
}
|
||||
|
||||
|
||||
// Protected: debounces the pin
|
||||
int Bounce::debounce() {
|
||||
|
||||
uint8_t newState = digitalRead(pin);
|
||||
if (state != newState ) {
|
||||
if (millis() - previous_millis >= interval_millis) {
|
||||
previous_millis = millis();
|
||||
state = newState;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
// The risingEdge method is true for one scan after the de-bounced input goes from off-to-on.
|
||||
bool Bounce::risingEdge() { return stateChanged && state; }
|
||||
// The fallingEdge method it true for one scan after the de-bounced input goes from on-to-off.
|
||||
bool Bounce::fallingEdge() { return stateChanged && !state; }
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
Main code by Thomas O Fredericks
|
||||
Rebounce and duration functions contributed by Eric Lowry
|
||||
Write function contributed by Jim Schimpf
|
||||
risingEdge and fallingEdge contributed by Tom Harkaway
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#ifndef Bounce_h
|
||||
#define Bounce_h
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
class Bounce
|
||||
{
|
||||
|
||||
public:
|
||||
// Initialize
|
||||
Bounce(uint8_t pin, unsigned long interval_millis );
|
||||
// Sets the debounce interval
|
||||
void interval(unsigned long interval_millis);
|
||||
// Updates the pin
|
||||
// Returns 1 if the state changed
|
||||
// Returns 0 if the state did not change
|
||||
int update();
|
||||
// Forces the pin to signal a change (through update()) in X milliseconds
|
||||
// even if the state does not actually change
|
||||
// Example: press and hold a button and have it repeat every X milliseconds
|
||||
void rebounce(unsigned long interval);
|
||||
// Returns the updated pin state
|
||||
int read();
|
||||
// Sets the stored pin state
|
||||
void write(int new_state);
|
||||
// Returns the number of milliseconds the pin has been in the current state
|
||||
unsigned long duration();
|
||||
// The risingEdge method is true for one scan after the de-bounced input goes from off-to-on.
|
||||
bool risingEdge();
|
||||
// The fallingEdge method it true for one scan after the de-bounced input goes from on-to-off.
|
||||
bool fallingEdge();
|
||||
|
||||
protected:
|
||||
int debounce();
|
||||
unsigned long previous_millis, interval_millis, rebounce_millis;
|
||||
uint8_t state;
|
||||
uint8_t pin;
|
||||
uint8_t stateChanged;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
Bounce library for Arduino
|
||||
|
||||
Version 1.5
|
||||
|
||||
by Thomas Ouellet Fredericks
|
||||
with contributions from:
|
||||
Eric Lowry
|
||||
Jim Schimpf
|
||||
Tom Harkaway
|
||||
|
||||
contact: mrtoftrash@gmail.com
|
||||
|
||||
See the online documentation here: http://www.arduino.cc/playground/Code/Bounce
|
||||
@@ -1,32 +0,0 @@
|
||||
#include <Bounce.h>
|
||||
|
||||
// This code turns a led on/off through a debounced button
|
||||
// Build the circuit indicated here: http://arduino.cc/en/Tutorial/Button
|
||||
|
||||
#define BUTTON 2
|
||||
#define LED 13
|
||||
|
||||
// Instantiate a Bounce object with a 5 millisecond debounce time
|
||||
Bounce bouncer = Bounce( BUTTON,5 );
|
||||
|
||||
void setup() {
|
||||
pinMode(BUTTON,INPUT);
|
||||
pinMode(LED,OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Update the debouncer
|
||||
bouncer.update ( );
|
||||
|
||||
// Get the update value
|
||||
int value = bouncer.read();
|
||||
|
||||
// Turn on or off the LED
|
||||
if ( value == HIGH) {
|
||||
digitalWrite(LED, HIGH );
|
||||
} else {
|
||||
digitalWrite(LED, LOW );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
#include <Bounce.h>
|
||||
#define BUTTON 2
|
||||
#define LED 13
|
||||
|
||||
int ledValue = LOW;
|
||||
|
||||
// This example changes the state of the LED everytime the button is pushed
|
||||
// Build the circuit indicated here: http://arduino.cc/en/Tutorial/Button
|
||||
|
||||
|
||||
Bounce bouncer = Bounce( BUTTON, 5 );
|
||||
|
||||
void setup() {
|
||||
pinMode(BUTTON,INPUT);
|
||||
pinMode(LED,OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
if ( bouncer.update() ) {
|
||||
if ( bouncer.read() == HIGH) {
|
||||
if ( ledValue == LOW ) {
|
||||
ledValue = HIGH;
|
||||
} else {
|
||||
ledValue = LOW;
|
||||
}
|
||||
digitalWrite(LED,ledValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
#include <Bounce.h>
|
||||
|
||||
/*
|
||||
This example uses a mercury tilt switch to detect the orientation
|
||||
of a robot. If you turn the bot over, it falls asleep to conserve
|
||||
battery life. If you have ever used a tilt switch before,
|
||||
you know they can be very "noisy" - they jump around a lot!
|
||||
The bounce library can handle sensing when a noisy switch has
|
||||
"settled down" with the "duration" method that tells you how long
|
||||
the pin has been in the current state.
|
||||
*/
|
||||
|
||||
const uint8_t ORIENTATION_PIN = 16;
|
||||
|
||||
Bounce orientation = Bounce( ORIENTATION_PIN, 50 );
|
||||
|
||||
int awake; // Are we awake based on our current orientation?
|
||||
|
||||
void setup() {
|
||||
|
||||
pinMode( ORIENTATION_PIN, INPUT );
|
||||
digitalWrite( ORIENTATION_PIN, HIGH ); // Activate Pull-Up
|
||||
|
||||
Serial.begin(19200);
|
||||
Serial.println( "Orientation Test " );
|
||||
Serial.println();
|
||||
|
||||
awake = orientation.read();
|
||||
|
||||
Serial.println( awake ? "Awake!" : "Asleep!" );
|
||||
|
||||
}
|
||||
|
||||
unsigned long lastKnock = 0;
|
||||
|
||||
void loop() {
|
||||
|
||||
orientation.update();
|
||||
|
||||
// has our orientation changed for more the 1/2 a second?
|
||||
if ( orientation.read() != awake && orientation.duration() > 500 ) {
|
||||
|
||||
awake = orientation.read();
|
||||
|
||||
if ( awake ) {
|
||||
|
||||
Serial.println( "Waking Up!" );
|
||||
// Do Something Here...
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Serial.println( "Falling Asleep" );
|
||||
// Do Something Here...
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,121 +0,0 @@
|
||||
|
||||
// Edge Test For use with the DANGER SHIELD
|
||||
|
||||
// This code turns a LED on and incraments number displayed on the 7-segment display
|
||||
// whenever either PB1 or PB2 is pressed. PB1 used the debounce library and PB2 does
|
||||
// not. PB1 will cleanly increment the displayed value. PB2 will not alway increment
|
||||
// the display because the switch is not debounced.
|
||||
//
|
||||
// The bounce library also detects the rising or falling edge of the input.
|
||||
// This is often called a one-shot and is usefull if you want something to only
|
||||
// happen once when a button is pressed or released. The risingEdge method is true
|
||||
// for only one scan when the input goes from off-to-on. The fallingEdge method is
|
||||
// true for only one scan when the input goes from on-to-off. Even if you are not
|
||||
// using the debounce feature the the library you need to call the update method
|
||||
// every scan for the edge detection to work.
|
||||
//
|
||||
// Notes:
|
||||
// The buttons on the Danger Shield pull the input to ground when they are pressed,
|
||||
// so they act like normally closed switches. If order to make them work like one
|
||||
// would expect, he tests for the button states are reversed. This also reversesd
|
||||
// the rising edge test on button1 to a falling edge test.
|
||||
//
|
||||
// Since PB2 is not debounced, the edge detection is done directly in the sketch.
|
||||
//
|
||||
|
||||
|
||||
#include <Bounce.h>
|
||||
|
||||
// This code turns a led on/off through a debounced button
|
||||
// Build the circuit indicated here: http://arduino.cc/en/Tutorial/Button
|
||||
|
||||
#define BUTTON1 10
|
||||
#define BUTTON2 11
|
||||
#define BUTTON3 12
|
||||
|
||||
#define BUZZER 3
|
||||
|
||||
#define LED1 5
|
||||
#define LED2 6
|
||||
|
||||
#define LATCH 7
|
||||
#define CLOCK 8
|
||||
#define DATA 4
|
||||
|
||||
|
||||
// Shift register bit values to display 0-9 on the seven-segment display
|
||||
const byte ledCharSet[16] = {
|
||||
B00111111, B00000110, B01011011, B01001111, B01100110,
|
||||
B01101101, B01111101, B00000111, B01111111, B01101111,
|
||||
B01110111, // a
|
||||
B01111100, // b
|
||||
B00111001, // c
|
||||
B01011110, // d
|
||||
B01111001, // e
|
||||
B01110001 // f
|
||||
};
|
||||
|
||||
byte pressCount= 0;
|
||||
bool lastButton2;
|
||||
|
||||
// Instantiate a Bounce object with a 5 millisecond debounce time
|
||||
Bounce bouncer1 = Bounce(BUTTON1, 5);
|
||||
|
||||
void setup() {
|
||||
pinMode(BUTTON1, INPUT);
|
||||
pinMode(LED1, OUTPUT);
|
||||
|
||||
pinMode(BUTTON2, INPUT);
|
||||
pinMode(LED2, OUTPUT);
|
||||
|
||||
pinMode(BUTTON3, INPUT);
|
||||
pinMode(BUZZER, OUTPUT);
|
||||
|
||||
pinMode(LATCH, OUTPUT);
|
||||
pinMode(CLOCK, OUTPUT);
|
||||
pinMode(DATA, OUTPUT);
|
||||
|
||||
lastButton2 = digitalRead(BUTTON2);
|
||||
|
||||
displayDigit(255, true);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
|
||||
// Update debouncer
|
||||
boolean button1Changed = bouncer1.update();
|
||||
|
||||
// Turn on or off the LED
|
||||
if ( !bouncer1.read()) {
|
||||
digitalWrite(LED1, HIGH);
|
||||
} else {
|
||||
digitalWrite(LED1, LOW);
|
||||
}
|
||||
|
||||
int buttonValue2 = digitalRead(BUTTON2);
|
||||
if (buttonValue2 == LOW) {
|
||||
digitalWrite(LED2, HIGH);
|
||||
} else {
|
||||
digitalWrite(LED2, LOW);
|
||||
}
|
||||
|
||||
if ( bouncer1.fallingEdge() || // rising edge of button 1
|
||||
(lastButton2 && !buttonValue2)) { // rising edge of button 2
|
||||
displayDigit(pressCount, false);
|
||||
pressCount++;
|
||||
if (pressCount > 15) { pressCount = 0; }
|
||||
}
|
||||
|
||||
lastButton2 = digitalRead(BUTTON2);
|
||||
|
||||
}
|
||||
|
||||
void displayDigit(byte value, boolean dp) {
|
||||
byte shiftData = 0;
|
||||
if (value <= 15) { shiftData = ledCharSet[value]; }
|
||||
if (dp) { shiftData |= B10000000; }
|
||||
digitalWrite(LATCH,LOW);
|
||||
shiftOut(DATA, CLOCK, MSBFIRST, ~shiftData);
|
||||
digitalWrite(LATCH,HIGH);
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
#include <Bounce.h>
|
||||
|
||||
// As long as the button is held down, the LED will blink
|
||||
// Build the circuit indicated here: http://arduino.cc/en/Tutorial/Button
|
||||
|
||||
#define BUTTON 2
|
||||
#define LED 13
|
||||
|
||||
// A variable to store the current LED state
|
||||
int ledState = LOW;
|
||||
|
||||
// Instantiate a Bounce object with a 5 millisecond debounce time
|
||||
Bounce bouncer = Bounce( BUTTON,5 );
|
||||
|
||||
void setup() {
|
||||
pinMode(BUTTON,INPUT);
|
||||
pinMode(LED,OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// Update and monitor a change of input
|
||||
if ( bouncer.update() ) {
|
||||
|
||||
// Get the state of the button
|
||||
int value = bouncer.read();
|
||||
|
||||
// Toggle the LED if the button is held
|
||||
if ( value == HIGH) {
|
||||
// Make the button retrigger in 500 milliseconds
|
||||
bouncer.rebounce(500);
|
||||
if ( ledState == LOW ) {
|
||||
ledState = HIGH;
|
||||
} else {
|
||||
ledState = LOW;
|
||||
}
|
||||
} else {
|
||||
ledState = LOW;
|
||||
}
|
||||
|
||||
digitalWrite(LED, ledState );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map For Debounce
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
Bounce KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
update KEYWORD2
|
||||
interval KEYWORD2
|
||||
read KEYWORD2
|
||||
write KEYWORD2
|
||||
rebounce KEYWORD2
|
||||
risingEdge KEYWORD2
|
||||
fallingEdge KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Instances (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
// Please read Bounce2.h for information about the liscence and authors
|
||||
|
||||
#if defined(ARDUINO) && ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
#include "Bounce2.h"
|
||||
|
||||
#define DEBOUNCED_STATE 0
|
||||
#define UNSTABLE_STATE 1
|
||||
#define STATE_CHANGED 3
|
||||
|
||||
|
||||
Bounce::Bounce()
|
||||
: previous_millis(0)
|
||||
, interval_millis(10)
|
||||
, state(0)
|
||||
, pin(0)
|
||||
{}
|
||||
|
||||
void Bounce::attach(int pin) {
|
||||
this->pin = pin;
|
||||
bool read = digitalRead(pin);
|
||||
state = 0;
|
||||
if (digitalRead(pin)) {
|
||||
state = _BV(DEBOUNCED_STATE) | _BV(UNSTABLE_STATE);
|
||||
}
|
||||
#ifdef BOUNCE_LOCK_OUT
|
||||
previous_millis = 0;
|
||||
#else
|
||||
previous_millis = millis();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Bounce::interval(uint16_t interval_millis)
|
||||
{
|
||||
this->interval_millis = interval_millis;
|
||||
}
|
||||
|
||||
bool Bounce::update()
|
||||
{
|
||||
#ifdef BOUNCE_LOCK_OUT
|
||||
state &= ~_BV(STATE_CHANGED);
|
||||
// Ignore everything if we are locked out
|
||||
if (millis() - previous_millis >= interval_millis) {
|
||||
bool currentState = digitalRead(pin);
|
||||
if ((bool)(state & _BV(DEBOUNCED_STATE)) != currentState) {
|
||||
previous_millis = millis();
|
||||
state ^= _BV(DEBOUNCED_STATE);
|
||||
state |= _BV(STATE_CHANGED);
|
||||
}
|
||||
}
|
||||
return state & _BV(STATE_CHANGED);
|
||||
#else
|
||||
// Read the state of the switch in a temporary variable.
|
||||
bool currentState = digitalRead(pin);
|
||||
state &= ~_BV(STATE_CHANGED);
|
||||
|
||||
// If the reading is different from last reading, reset the debounce counter
|
||||
if ( currentState != (bool)(state & _BV(UNSTABLE_STATE)) ) {
|
||||
previous_millis = millis();
|
||||
state ^= _BV(UNSTABLE_STATE);
|
||||
} else
|
||||
if ( millis() - previous_millis >= interval_millis ) {
|
||||
// We have passed the threshold time, so the input is now stable
|
||||
// If it is different from last state, set the STATE_CHANGED flag
|
||||
if ((bool)(state & _BV(DEBOUNCED_STATE)) != currentState) {
|
||||
previous_millis = millis();
|
||||
state ^= _BV(DEBOUNCED_STATE);
|
||||
state |= _BV(STATE_CHANGED);
|
||||
}
|
||||
}
|
||||
|
||||
return state & _BV(STATE_CHANGED);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Bounce::read()
|
||||
{
|
||||
return state & _BV(DEBOUNCED_STATE);
|
||||
}
|
||||
|
||||
bool Bounce::rose()
|
||||
{
|
||||
return ( state & _BV(DEBOUNCED_STATE) ) && ( state & _BV(STATE_CHANGED));
|
||||
}
|
||||
|
||||
bool Bounce::fell()
|
||||
{
|
||||
return !( state & _BV(DEBOUNCED_STATE) ) && ( state & _BV(STATE_CHANGED));
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 thomasfredericks
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
Main code by Thomas O Fredericks (tof@t-o-f.info)
|
||||
Previous contributions by Eric Lowry, Jim Schimpf and Tom Harkaway
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#ifdef BOUNCE_LOCK
|
||||
#error You are using the invalid BOUNCE_LOCK-OUT define. Please update your sources to use BOUNCE_LOCK_OUT
|
||||
#endif
|
||||
|
||||
// Uncomment the following line for "LOCK-OUT" debounce method
|
||||
//#define BOUNCE_LOCK_OUT
|
||||
|
||||
|
||||
#ifndef Bounce2_h
|
||||
#define Bounce2_h
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
class Bounce
|
||||
{
|
||||
public:
|
||||
// Create an instance of the bounce library
|
||||
Bounce();
|
||||
|
||||
// Attach to a pin (and also sets initial state)
|
||||
void attach(int pin);
|
||||
|
||||
// Sets the debounce interval
|
||||
void interval(uint16_t interval_millis);
|
||||
|
||||
// Updates the pin
|
||||
// Returns 1 if the state changed
|
||||
// Returns 0 if the state did not change
|
||||
bool update();
|
||||
|
||||
// Returns the updated pin state
|
||||
bool read();
|
||||
|
||||
// Returns the falling pin state
|
||||
bool fell();
|
||||
|
||||
// Returns the rising pin state
|
||||
bool rose();
|
||||
|
||||
protected:
|
||||
unsigned long previous_millis;
|
||||
uint16_t interval_millis;
|
||||
uint8_t state;
|
||||
uint8_t pin;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,20 +0,0 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 thomasfredericks
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -1,9 +0,0 @@
|
||||
DOCUMENTATION
|
||||
=====================
|
||||
|
||||
https://github.com/thomasfredericks/Bounce-Arduino-Wiring/wiki
|
||||
|
||||
DOWNLOAD
|
||||
=====================
|
||||
|
||||
https://github.com/thomasfredericks/Bounce-Arduino-Wiring/archive/master.zip
|
||||
@@ -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/Bounce-Arduino-Wiring
|
||||
#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 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
|
||||
// Detect the falling edge
|
||||
|
||||
// Include the Bounce2 library found here :
|
||||
// https://github.com/thomasfredericks/Bounce-Arduino-Wiring
|
||||
#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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
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/Bounce-Arduino-Wiring
|
||||
#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();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
Put the "Bounce2" folder in your Arduino or Wiring "libraries" folder.
|
||||
@@ -1,37 +1,232 @@
|
||||
BOUNCE 2
|
||||
=====================
|
||||
# Bounce2
|
||||
|
||||
Debouncing library for Arduino or Wiring
|
||||
Debouncing library for Arduino and Wiring by Thomas Ouellet Fredericks and many [contributors](https://github.com/thomasfredericks/Bounce2/graphs/contributors).
|
||||
|
||||
by Thomas Ouellet Fredericks
|
||||
The mechanical part of buttons and switches vibrate slightly when closed or opened causing multiple undesired false states (similar to noise). This library filters out these undesired state changes. You can learn more about debouncing here:
|
||||
* [John Errington's Experiments with an Arduino - Using digital inputs: Switch bounce and solutions to it](http://www.skillbank.co.uk/arduino/switchbounce.htm)
|
||||
* [Wikipedia article on contact Debouncing](http://en.wikipedia.org/wiki/Debounce#Contact_bounce)
|
||||
|
||||
with contributions from:
|
||||
The library is composed of three classes:
|
||||
* `Bounce2::Button` : The class that most people will use. It is the most feature rich class for deboucing hardware buttons.
|
||||
* `Debouncer` : The code that does the actual debouncing. Only advanced users should use this class for creating their own implememtations.
|
||||
* `Bounce` : This class links the `Debouncer` class to a hardware pin on your board. It is odly named because it needs to be backward compatible to previous versions of this library.
|
||||
|
||||
Eric Lowry, Jim Schimpf and Tom Harkaway
|
||||
# Need Help?
|
||||
|
||||
Please post your usage questions on the [Arduino Forums](https://forum.arduino.cc/latest).
|
||||
|
||||
# Installation
|
||||
|
||||
Install through your software's Library Manager or download the latest version [here](https://github.com/thomasfredericks/Bounce2/archive/master.zip) and put the "Bounce2" folder in your "libraries" folder.
|
||||
|
||||
Please note that the original version of this library (Bounce 1) is included in the "extras" folder of the download but not supported anymore.
|
||||
|
||||
# Basic Use
|
||||
|
||||
## Global Space
|
||||
|
||||
```cpp
|
||||
#include <Bounce2.h>
|
||||
Bounce2::Button button = Bounce2::Button(); // INSTANTIATE A Bounce2::Button OBJECT
|
||||
```
|
||||
|
||||
## Configuration in `setup()`
|
||||
|
||||
In the code sample below :
|
||||
* Change *PIN* to the hardware pin of the button.
|
||||
* Change *PIN_MODE* to `INPUT_PULLUP` if using an internal pullup, or `INPUT` if using an external pullup.
|
||||
* Change *INTERVAL_IN_MS* to the debounce interval in millisecons. `5` is a good value.
|
||||
* Change *PRESSED_STATE* to `LOW` if the button outputs a `LOW` when pressed, or to `HIGH` if the button outputs a `HIGH` when pressed.
|
||||
|
||||
```cpp
|
||||
button.attach ( PIN , PIN_MODE );
|
||||
button.interval( INTERVAL_IN_MS );
|
||||
button.setPressedState( PRESSED_STATE );
|
||||
```
|
||||
|
||||
|
||||
HAVE A QUESTION?
|
||||
=====================
|
||||
Please post your questions here :
|
||||
http://forum.arduino.cc/index.php?topic=266132.0
|
||||
## Use in `loop()`
|
||||
|
||||
DOWNLOAD
|
||||
=====================
|
||||
```cpp
|
||||
// UPDATE THE BUTTON BY CALLING .update() AT THE BEGINNING OF THE LOOP:
|
||||
button.update();
|
||||
|
||||
Download the latest version (version 2) here :
|
||||
// IF THE BUTTON WAS PRESSED THIS LOOP:
|
||||
if ( button.pressed() ) {
|
||||
// DO SOMETHING IF THE BUTTON WAS PRESSED THIS LOOP...
|
||||
}
|
||||
```
|
||||
|
||||
https://github.com/thomasfredericks/Bounce-Arduino-Wiring/archive/master.zip
|
||||
# Examples
|
||||
|
||||
## A Button Toggling a LED
|
||||
|
||||
```cpp
|
||||
/*
|
||||
DESCRIPTION
|
||||
====================
|
||||
This is an example of the Bounce2::Button class.
|
||||
When the user presses a physical button, it toggles a LED on or off.
|
||||
The Button class matches an electrical state to a physical action.
|
||||
Use .setPressedState(LOW or HIGH) to set the detection state for when the button is pressed.
|
||||
|
||||
INSTRUCTIONS
|
||||
====================
|
||||
Set BUTTON_PIN to the pin attached to the button.
|
||||
Set LED_PIN to the pin attached to a LED.
|
||||
|
||||
*/
|
||||
|
||||
// Include the Bounce2 library found here :
|
||||
// https://github.com/thomasfredericks/Bounce2
|
||||
#include <Bounce2.h>
|
||||
|
||||
// INSTANTIATE A Button OBJECT
|
||||
Bounce2::Button button = Bounce2::Button();
|
||||
|
||||
// WE WILL attach() THE BUTTON TO THE FOLLOWING PIN IN setup()
|
||||
#define BUTTON_PIN 39
|
||||
|
||||
// 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
|
||||
|
||||
// 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();
|
||||
|
||||
if ( button.pressed() ) {
|
||||
|
||||
// TOGGLE THE LED STATE :
|
||||
ledState = !ledState; // SET ledState TO THE OPPOSITE OF ledState
|
||||
digitalWrite(LED_PIN,ledState);
|
||||
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## More Examples
|
||||
|
||||
You can find more examples in the **examples** folder.
|
||||
|
||||
# Documentation
|
||||
|
||||
## Bounce2::Button
|
||||
|
||||
The `Bounce2::Button` class extends `Bounce` and adds `pressed()` and `released()` methods. It is the most feature rich class of the library.
|
||||
|
||||
| Method | Description |
|
||||
| --------------- | --------------- |
|
||||
| `Button()` | Create an instance of the Button class. By default, the pressed state is matched to a HIGH electrical level. |
|
||||
| `void` `update()` | Updates the pin's state. Because Bounce does not use interrupts, you have to "update" the object before reading its value and it has to be done as often as possible (that means to include it in your `loop()`). Only call `update()` for each Bounce instance once per `loop()`. |
|
||||
| `void` `setPressedState(bool state)` | Set the electrical state (HIGH/LOW) that corresponds to a physical press. By default, the pressed state is matched to a HIGH electrical level. |
|
||||
| `bool` `getPressedState()` | Get the electrical state (HIGH/LOW) that corresponds to a physical press. |
|
||||
| `bool ` `isPressed() ` | Returns true if the button **is** currently pressed. |
|
||||
| `bool ` `pressed()` | Returns true if the button **was** pressed |
|
||||
| `bool ` `released()` | Returns true if the button **was** released |
|
||||
| `void` `attach(int pin, int mode)` | Attach to a pin and sets that pin's mode (INPUT, INPUT_PULLUP or OUTPUT). |
|
||||
| `int` `getPin()` | Return pin that this instance is attached to. |
|
||||
| `void` `interval ( uint16_t interval_millis )` | Sets the debounce interval in milliseconds. |
|
||||
| `unsigned long` `previousDuration()` | Returns the duration in milliseconds of the previous state. |
|
||||
| `unsigned long` `currentDuration()` | Returns the duration in milliseconds of the current state. Is reset to 0 when the state changes. |
|
||||
| `bool` `changed()` | Returns true if the state changed on last update. |
|
||||
| `bool` `read()` | Returns the pin's state (HIGH or LOW). |
|
||||
| `bool` `fell()` | Returns true if pin signal transitions from high to low since the last update. |
|
||||
| `bool` `rose()` | Returns true if pin signal transitions from low to high since the last update. |
|
||||
|
||||
|
||||
DOCUMENTATION
|
||||
=====================
|
||||
## Bounce
|
||||
|
||||
The latest version (version 2) documentation can be found here :
|
||||
The `Bounce` class extends `Debouncer` and links it to a hardware pin. This class is odly named, but it will be kept that so it stays compatible with previous code.
|
||||
|
||||
https://github.com/thomasfredericks/Bounce-Arduino-Wiring/wiki
|
||||
| Method | Description |
|
||||
| --------------- | --------------- |
|
||||
| `Bounce()` | Create an instance of the Bounce class. |
|
||||
| `void` `update()` | Updates the pin's state. Because Bounce does not use interrupts, you have to "update" the object before reading its value and it has to be done as often as possible (that means to include it in your `loop()`). Only call `update()` for each Bounce instance once per `loop()`. |
|
||||
| `void` `attach(int pin, int mode)` | Attach to a pin and sets that pin's mode (INPUT, INPUT_PULLUP or OUTPUT). |
|
||||
| `int` `getPin()` | Return pin that this instance is attached to. |
|
||||
| `void` `interval ( uint16_t interval_millis )` | Sets the debounce interval in milliseconds. |
|
||||
| `unsigned long` `previousDuration()` | Returns the duration in milliseconds of the previous state. |
|
||||
| `unsigned long` `currentDuration()` | Returns the duration in milliseconds of the current state. Is reset to 0 when the state changes. |
|
||||
| `bool` `changed()` | Returns true if the state changed on last update. |
|
||||
| `bool` `read()` | Returns the pin's state (HIGH or LOW). |
|
||||
| `bool` `fell()` | Returns true if pin signal transitions from high to low since the last update. |
|
||||
| `bool` `rose()` | Returns true if pin signal transitions from low to high since the last update. |
|
||||
|
||||
## Debouncer
|
||||
|
||||
The `Debouncer` class. Just the debouncing code separated from all hardware.
|
||||
|
||||
| Method | Description |
|
||||
| --------------- | --------------- |
|
||||
| `Debouncer()` | Create an instance of the Debouncer class.|
|
||||
| `void` `update()` | Updates the pin's state. Because Bounce does not use interrupts, you have to "update" the object before reading its value and it has to be done as often as possible (that means to include it in your `loop()`). Only call `update()` for each Bounce instance once per `loop()`. |
|
||||
| `void` `interval ( uint16_t interval_millis )` | Sets the debounce interval in milliseconds. |
|
||||
| `unsigned long` `previousDuration()` | Returns the duration in milliseconds of the previous state. |
|
||||
| `unsigned long` `currentDuration()` | Returns the duration in milliseconds of the current state. Is reset to 0 when the state changes. |
|
||||
| `bool` `changed()` | Returns true if the state changed on last update. |
|
||||
| `bool` `read()` | Returns the pin's state (HIGH or LOW). |
|
||||
| `bool` `fell()` | Returns true if pin signal transitions from high to low since the last update. |
|
||||
| `bool` `rose()` | Returns true if pin signal transitions from low to high since the last update. |
|
||||
|
||||
|
||||
ABOUT BOUNCE 1 (ORIGINAL VERSION)
|
||||
=====================
|
||||
# Alternate Algorithms
|
||||
|
||||
The following alternate debouncing algorithms are for **advanced** users or specific cases.
|
||||
|
||||
## Stable Interval
|
||||
|
||||
By default, the Bounce library uses a stable interval to process the debouncing. This is simpler to understand and can cancel unwanted noise.
|
||||
|
||||

|
||||
|
||||
## Lock-out Interval
|
||||
|
||||
By defining "#define BOUNCE_LOCK_OUT" in "Bounce.h" you can activate an alternative debouncing method. This method is a lot more responsive, but does not cancel noise.
|
||||
|
||||
```
|
||||
#define BOUNCE_LOCK_OUT
|
||||
```
|
||||
|
||||

|
||||
|
||||
## Prompt Detection
|
||||
|
||||
By defining "#define BOUNCE_WITH_PROMPT_DETECTION" in "Bounce.h" you can activate an alternative debouncing method. Button state changes are available immediately so long as the previous state has been stable for the timeout period. Otherwise the state will be updated as soon as the timeout period allows.
|
||||
|
||||
* Able to report acurate switch time normally with no delay.
|
||||
* Use when accurate switch transition timing is important.
|
||||
|
||||
```
|
||||
#define BOUNCE_WITH_PROMPT_DETECTION
|
||||
```
|
||||
|
||||
|
||||
The original version of Bounce (Bounce 1) is included but not supported anymore.
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
title: Bounce2 Arduino & Wiring Library
|
||||
description: Debouncing library for Arduino and Wiring.
|
||||
show_downloads: true
|
||||
google_analytics:
|
||||
theme: jekyll-theme-leap-day
|
||||
@@ -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
|
||||
int 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,77 @@
|
||||
|
||||
/*
|
||||
DESCRIPTION
|
||||
====================
|
||||
This is an example of the Bounce2::Button class.
|
||||
When the user presses a physical button, it toggles a LED on or off.
|
||||
The Button class matches an electrical state to a physical action.
|
||||
Use .setPressedState(LOW or HIGH) to set the detection state for when the button is pressed.
|
||||
|
||||
|
||||
INSCRUCTIONS
|
||||
====================
|
||||
|
||||
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 FROM THE Bounce2 NAMESPACE
|
||||
Bounce2::Button button = Bounce2::Button();
|
||||
|
||||
|
||||
|
||||
// SET A VARIABLE TO STORE THE LED STATE
|
||||
int 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>);
|
||||
// WHICH IS LOW IN THIS EXAMPLE AS SET WITH button.setPressedState(LOW); IN setup()
|
||||
if ( button.pressed() ) {
|
||||
|
||||
// TOGGLE THE LED STATE :
|
||||
ledState = !ledState; // SET ledState TO THE OPPOSITE OF ledState
|
||||
digitalWrite(LED_PIN,ledState); // WRITE THE NEW ledState
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
|
||||
/*
|
||||
DESCRIPTION
|
||||
====================
|
||||
Simple example of the Bounce library that switches on a LED when
|
||||
the decounced input is held for more than 1000 milliseconds.
|
||||
|
||||
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
|
||||
int 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();
|
||||
|
||||
// GET THE STATE WITH <Bounce.read()>
|
||||
int debouncedState = bounce.read();
|
||||
|
||||
// <Bounce>.duration() RETURNS THE TIME IN MILLISECONDS THE CURRENT STATE HAS BEEN HELD.
|
||||
// SO WE CHECK IF THE STATE IS LOW AND IF IT HAS BEEN LOW FOR MORE THAN 1 SECOND.
|
||||
if ( debouncedState == LOW && bounce.currentDuration() > 1000 ) {
|
||||
digitalWrite(LED_PIN,HIGH); // TURN THE LED ON
|
||||
} else {
|
||||
digitalWrite(LED_PIN,LOW); // TURN THE LED OFF
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
// Le code de base pour le M5Stack Atom
|
||||
|
||||
// Inclure la librairie M5 (version pour M5Atom) :
|
||||
// https://github.com/m5stack/M5Atom
|
||||
#include <M5Atom.h>
|
||||
|
||||
// Inclure la librairie FastLED qui va gérer le pixel :
|
||||
// https://github.com/FastLED/FastLED
|
||||
#include <FastLED.h>
|
||||
|
||||
// Un tableau qui contient une variable de type CRGB.
|
||||
// Il y a un seul pixel, mais il doit être dans un tableau.
|
||||
// CRGB est un type de couleur défini par la lirairie FastLed :
|
||||
// https://github.com/FastLED/FastLED/wiki/Pixel-reference#crgb-reference
|
||||
CRGB mesPixels[1];
|
||||
|
||||
#include <Bounce2.h>
|
||||
Bounce2::Button button = Bounce2::Button(); // INSTANTIATE A Bounce2::Button OBJECT
|
||||
|
||||
bool ledToggle = false;
|
||||
|
||||
void setup() {
|
||||
// Démarrer la libraire M5 avec toutes les options de pré-configuration désactivées :
|
||||
M5.begin(false, false, false);
|
||||
|
||||
// Démarrer la connexion sérielle :
|
||||
Serial.begin(115200);
|
||||
|
||||
// Ajouter le pixel (il y en a un seul) du M5Atom à la librairie FastLED :
|
||||
FastLED.addLeds<WS2812, DATA_PIN, GRB>(mesPixels, 1);
|
||||
|
||||
// Animation de démarrage
|
||||
while (millis() < 5000) {
|
||||
mesPixels[0] = CHSV((millis() / 5) % 255, 255, 255 - (millis() * 255 / 5000));
|
||||
FastLED.show();
|
||||
delay(50);
|
||||
}
|
||||
mesPixels[0] = CRGB(0, 0, 0);
|
||||
FastLED.show();
|
||||
|
||||
button.attach(32, INPUT_PULLUP);
|
||||
button.interval(5);
|
||||
button.setPressedState(LOW);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Toujours inclure M5.update() au début de loop() :
|
||||
M5.update();
|
||||
|
||||
// UPDATE THE BUTTON BY CALLING .update() AT THE BEGINNING OF THE LOOP:
|
||||
button.update();
|
||||
|
||||
// IF THE BUTTON WAS PRESSED THIS LOOP:
|
||||
if (button.pressed()) {
|
||||
// DO SOMETHING IF THE BUTTON WAS PRESSED THIS LOOP...
|
||||
|
||||
if (ledToggle) {
|
||||
ledToggle = false;
|
||||
mesPixels[0] = CRGB(0, 0, 0);
|
||||
} else {
|
||||
ledToggle = true;
|
||||
mesPixels[0] = CRGB(255, 255, 255);
|
||||
}
|
||||
|
||||
FastLED.show();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
|
||||
/*
|
||||
DESCRIPTION
|
||||
====================
|
||||
When the debounced input goes from LOW to HIGH, the LED will turn on for the same time
|
||||
the debounced input was held LOW.
|
||||
|
||||
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 INTERVAL FOR HOW LONG TO KEEP THE LED HIGH
|
||||
unsigned long ledHighInterval;
|
||||
|
||||
// SET A VARIABLE TO STORE THE START TIME WHEN THE LED WAS TURNED HIGH
|
||||
unsigned long ledHighLastTime;
|
||||
|
||||
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, LOW);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Update the Bounce instance (YOU MUST DO THIS EVERY LOOP)
|
||||
bounce.update();
|
||||
|
||||
// <Bounce>.rose() RETURNS true IF THE STATE JUST WENT FROM LOW TO HIGH
|
||||
if ( bounce.rose() ) {
|
||||
digitalWrite(LED_PIN, HIGH); // TURN ON THE LED
|
||||
ledHighLastTime = millis();
|
||||
ledHighInterval = bounce.previousDuration();
|
||||
}
|
||||
|
||||
// IF WE HAVE TO BLINK THE LED
|
||||
if ( millis() - ledHighLastTime > ledHighInterval ) {
|
||||
digitalWrite(LED_PIN, LOW);
|
||||
} else {
|
||||
digitalWrite(LED_PIN, HIGH);
|
||||
}
|
||||
|
||||
}
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
|
||||
/*
|
||||
DESCRIPTION
|
||||
====================
|
||||
Simple example of the Bounce library that switches the state of a LED
|
||||
when the debounced input goes from LOW to HIGH.
|
||||
|
||||
Also if the debounced input was previously held LOW for more than 1000 milliseconds,
|
||||
the LED will blink.
|
||||
|
||||
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
|
||||
int ledState = LOW;
|
||||
|
||||
// SET A VARIABLE TO STORE THE BLINKING STATE
|
||||
bool blinkLed = false;
|
||||
// SET A VARIABLE TO STORE THE LAST TIME THE LED BLINKED
|
||||
unsigned long blinkLedLastTime;
|
||||
|
||||
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 HIGH
|
||||
if ( deboucedInput == HIGH ) {
|
||||
ledState = !ledState; // SET ledState TO THE OPPOSITE OF ledState
|
||||
digitalWrite(LED_PIN,ledState); // WRITE THE NEW ledState
|
||||
// IF THE DURATION OF THE PREVIOUS STATE (LOW IN THIS CASE) WAS HELD LONGER THAN 1000 MILLISECONDS:
|
||||
if ( bounce.previousDuration() > 1000 ) blinkLed = true;
|
||||
else blinkLed = false;
|
||||
}
|
||||
}
|
||||
|
||||
// IF WE HAVE TO BLINK THE LED
|
||||
if ( blinkLed ) {
|
||||
if ( millis() - blinkLedLastTime > 500 ) {
|
||||
blinkLedLastTime = millis();
|
||||
ledState = !ledState; // SET ledState TO THE OPPOSITE OF ledState
|
||||
digitalWrite(LED_PIN,ledState); // WRITE THE NEW ledState
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
|
||||
// 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(25); // Use a debounce interval of 25 milliseconds
|
||||
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ Open the Serial Monitor (57600 baud) for debug messages.
|
||||
*/
|
||||
|
||||
// Include the Bounce2 library found here :
|
||||
// https://github.com/thomasfredericks/Bounce-Arduino-Wiring
|
||||
// https://github.com/thomasfredericks/Bounce2
|
||||
#include <Bounce2.h>
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 9.1 KiB After Width: | Height: | Size: 9.1 KiB |
|
Before Width: | Height: | Size: 47 KiB After Width: | Height: | Size: 47 KiB |
@@ -6,18 +6,26 @@
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
Bounce KEYWORD1
|
||||
|
||||
Bounce KEYWORD1
|
||||
Bounce2 KEYWORD1
|
||||
Button KEYWORD1
|
||||
Bounce2NameSpace KEYWORD1
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
update KEYWORD2
|
||||
interval KEYWORD2
|
||||
read KEYWORD2
|
||||
attach KEYWORD2
|
||||
update KEYWORD2
|
||||
interval KEYWORD2
|
||||
read KEYWORD2
|
||||
attach KEYWORD2
|
||||
rose KEYWORD2
|
||||
fell KEYWORD2
|
||||
duration KEYWORD2
|
||||
pressed KEYWORD2
|
||||
released KEYWORD2
|
||||
setPressedState KEYWORD2
|
||||
currentDuration KEYWORD2
|
||||
previousDuration KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Instances (KEYWORD2)
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "Bounce2",
|
||||
"keywords": "bounce, signal, input, ouput",
|
||||
"description": "Debouncing library for Arduino or Wiring",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/thomasfredericks/Bounce2.git"
|
||||
},
|
||||
"version": "2.72",
|
||||
"exclude": [
|
||||
"*.png",
|
||||
"*.zip"
|
||||
],
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
name=Bounce2
|
||||
version=2.72
|
||||
author=Thomas O Fredericks <tof@t-o-f.info> with contributions from Eric Lowry, Jim Schimpf, Tom Harkaway, Joachim Krüger and MrGradgrind.
|
||||
maintainer=Thomas O Fredericks <tof@t-o-f.info>
|
||||
sentence=Debouncing library for Arduino and Wiring.
|
||||
paragraph=Debouncing switches and toggles is important.
|
||||
category=Signal Input/Output
|
||||
includes=Bounce2.h
|
||||
url=https://github.com/thomasfredericks/Bounce2
|
||||
architectures=*
|
||||
+155
@@ -0,0 +1,155 @@
|
||||
// Please read Bounce2.h for information about the liscence and authors
|
||||
|
||||
|
||||
#include "Bounce2.h"
|
||||
|
||||
//////////////
|
||||
// DEBOUNCE //
|
||||
//////////////
|
||||
|
||||
Debouncer::Debouncer():previous_millis(0)
|
||||
, interval_millis(10)
|
||||
, state(0) {}
|
||||
|
||||
void Debouncer::interval(uint16_t interval_millis)
|
||||
{
|
||||
this->interval_millis = interval_millis;
|
||||
}
|
||||
|
||||
void Debouncer::begin() {
|
||||
state = 0;
|
||||
if (readCurrentState()) {
|
||||
setStateFlag(DEBOUNCED_STATE | UNSTABLE_STATE);
|
||||
}
|
||||
|
||||
#ifdef BOUNCE_LOCK_OUT
|
||||
previous_millis = 0;
|
||||
#else
|
||||
previous_millis = millis();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Debouncer::update()
|
||||
{
|
||||
|
||||
unsetStateFlag(CHANGED_STATE);
|
||||
#ifdef BOUNCE_LOCK_OUT
|
||||
|
||||
// Ignore everything if we are locked out
|
||||
if (millis() - previous_millis >= interval_millis) {
|
||||
bool currentState = readCurrentState();
|
||||
if ( currentState != getStateFlag(DEBOUNCED_STATE) ) {
|
||||
previous_millis = millis();
|
||||
changeState();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#elif defined BOUNCE_WITH_PROMPT_DETECTION
|
||||
// Read the state of the switch port into a temporary variable.
|
||||
bool readState = readCurrentState();
|
||||
|
||||
|
||||
if ( readState != getStateFlag(DEBOUNCED_STATE) ) {
|
||||
// We have seen a change from the current button state.
|
||||
|
||||
if ( millis() - previous_millis >= interval_millis ) {
|
||||
// We have passed the time threshold, so a new change of state is allowed.
|
||||
// set the STATE_CHANGED flag and the new DEBOUNCED_STATE.
|
||||
// This will be prompt as long as there has been greater than interval_misllis ms since last change of input.
|
||||
// Otherwise debounced state will not change again until bouncing is stable for the timeout period.
|
||||
changeState();
|
||||
}
|
||||
}
|
||||
|
||||
// If the readState is different from previous readState, reset the debounce timer - as input is still unstable
|
||||
// and we want to prevent new button state changes until the previous one has remained stable for the timeout.
|
||||
if ( readState != getStateFlag(UNSTABLE_STATE) ) {
|
||||
// Update Unstable Bit to macth readState
|
||||
toggleStateFlag(UNSTABLE_STATE);
|
||||
previous_millis = millis();
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
// Read the state of the switch in a temporary variable.
|
||||
bool currentState = readCurrentState();
|
||||
|
||||
|
||||
// If the reading is different from last reading, reset the debounce counter
|
||||
if ( currentState != getStateFlag(UNSTABLE_STATE) ) {
|
||||
previous_millis = millis();
|
||||
toggleStateFlag(UNSTABLE_STATE);
|
||||
} else
|
||||
if ( millis() - previous_millis >= interval_millis ) {
|
||||
// We have passed the threshold time, so the input is now stable
|
||||
// If it is different from last state, set the STATE_CHANGED flag
|
||||
if (currentState != getStateFlag(DEBOUNCED_STATE) ) {
|
||||
previous_millis = millis();
|
||||
|
||||
|
||||
changeState();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
return changed();
|
||||
|
||||
}
|
||||
|
||||
// WIP HELD
|
||||
unsigned long Debouncer::previousDuration() const {
|
||||
return durationOfPreviousState;
|
||||
}
|
||||
|
||||
unsigned long Debouncer::currentDuration() const {
|
||||
return (millis() - stateChangeLastTime);
|
||||
}
|
||||
|
||||
inline void Debouncer::changeState() {
|
||||
toggleStateFlag(DEBOUNCED_STATE);
|
||||
setStateFlag(CHANGED_STATE) ;
|
||||
durationOfPreviousState = millis() - stateChangeLastTime;
|
||||
stateChangeLastTime = millis();
|
||||
}
|
||||
|
||||
bool Debouncer::read() const
|
||||
{
|
||||
return getStateFlag(DEBOUNCED_STATE);
|
||||
}
|
||||
|
||||
bool Debouncer::rose() const
|
||||
{
|
||||
return getStateFlag(DEBOUNCED_STATE) && getStateFlag(CHANGED_STATE);
|
||||
}
|
||||
|
||||
bool Debouncer::fell() const
|
||||
{
|
||||
return !getStateFlag(DEBOUNCED_STATE) && getStateFlag(CHANGED_STATE);
|
||||
}
|
||||
|
||||
////////////
|
||||
// BOUNCE //
|
||||
////////////
|
||||
|
||||
|
||||
Bounce::Bounce()
|
||||
: pin(0)
|
||||
{}
|
||||
|
||||
void Bounce::attach(int pin) {
|
||||
this->pin = pin;
|
||||
|
||||
// SET INITIAL STATE
|
||||
begin();
|
||||
}
|
||||
|
||||
void Bounce::attach(int pin, int mode){
|
||||
setPinMode(pin, mode);
|
||||
this->attach(pin);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+334
@@ -0,0 +1,334 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 thomasfredericks
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
Main code by Thomas O Fredericks (tof@t-o-f.info)
|
||||
Previous contributions by Eric Lowry, Jim Schimpf and Tom Harkaway
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
|
||||
#ifndef Bounce2_h
|
||||
#define Bounce2_h
|
||||
|
||||
#if defined(ARDUINO) && ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
// Uncomment the following line for "LOCK-OUT" debounce method
|
||||
//#define BOUNCE_LOCK_OUT
|
||||
|
||||
// Uncomment the following line for "BOUNCE_WITH_PROMPT_DETECTION" debounce method
|
||||
//#define BOUNCE_WITH_PROMPT_DETECTION
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
/**
|
||||
@example bounce_basic.ino
|
||||
Basic example of the Bounce class.
|
||||
*/
|
||||
|
||||
/**
|
||||
@example button_basic.ino
|
||||
Basic example of the Button class.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@brief The Debouce class. Just the deboucing code separated from all harware.
|
||||
*/
|
||||
class Debouncer
|
||||
{
|
||||
// Note : this is private as it migh change in the future
|
||||
private:
|
||||
static const uint8_t DEBOUNCED_STATE = 0b00000001; // Final returned calculated debounced state
|
||||
static const uint8_t UNSTABLE_STATE = 0b00000010; // Actual last state value behind the scene
|
||||
static const uint8_t CHANGED_STATE = 0b00000100; // The DEBOUNCED_STATE has changed since last update()
|
||||
|
||||
// Note : this is private as it migh change in the future
|
||||
private:
|
||||
inline void changeState();
|
||||
inline void setStateFlag(const uint8_t flag) {state |= flag;}
|
||||
inline void unsetStateFlag(const uint8_t flag) {state &= ~flag;}
|
||||
inline void toggleStateFlag(const uint8_t flag) {state ^= flag;}
|
||||
inline bool getStateFlag(const uint8_t flag) const {return((state & flag) != 0);}
|
||||
|
||||
public:
|
||||
/*!
|
||||
@brief Create an instance of the Debounce class.
|
||||
|
||||
@endcode
|
||||
*/
|
||||
Debouncer();
|
||||
|
||||
/**
|
||||
@brief Sets the debounce interval in milliseconds.
|
||||
|
||||
@param interval_millis
|
||||
The interval time in milliseconds.
|
||||
|
||||
*/
|
||||
void interval(uint16_t interval_millis);
|
||||
|
||||
/*!
|
||||
@brief Updates the pin's state.
|
||||
|
||||
Because Bounce does not use interrupts, you have to "update" the object before reading its value and it has to be done as often as possible (that means to include it in your loop()). Only call update() once per loop().
|
||||
|
||||
@return True if the pin changed state.
|
||||
*/
|
||||
|
||||
bool update();
|
||||
|
||||
/**
|
||||
@brief Returns the pin's state (HIGH or LOW).
|
||||
|
||||
@return HIGH or LOW.
|
||||
*/
|
||||
bool read() const;
|
||||
|
||||
/**
|
||||
@brief Returns true if pin signal transitions from high to low.
|
||||
*/
|
||||
bool fell() const;
|
||||
|
||||
/**
|
||||
@brief Returns true if pin signal transitions from low to high.
|
||||
*/
|
||||
bool rose() const;
|
||||
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
@brief Returns true if the state changed on last update.
|
||||
|
||||
@return True if the state changed on last update. Otherwise, returns false.
|
||||
*/
|
||||
bool changed( ) const { return getStateFlag(CHANGED_STATE); }
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@brief Returns the duration in milliseconds of the current state.
|
||||
|
||||
Is reset to 0 once the pin rises ( rose() ) or falls ( fell() ).
|
||||
|
||||
@return The duration in milliseconds (unsigned long) of the current state.
|
||||
*/
|
||||
|
||||
unsigned long currentDuration() const;
|
||||
|
||||
|
||||
/**
|
||||
@brief Returns the duration in milliseconds of the previous state.
|
||||
|
||||
Takes the values of duration() once the pin changes state.
|
||||
|
||||
@return The duration in milliseconds (unsigned long) of the previous state.
|
||||
*/
|
||||
unsigned long previousDuration() const;
|
||||
|
||||
/**
|
||||
@brief DEPRECATED (i.e. do not use). Renamed currentDuration().
|
||||
|
||||
This member function is DEPRECATED will be removed next major version. DO NOT USE IT. USE currentDuration() INSTEAD.
|
||||
It was renamed to avoid confusion with previousDuration().
|
||||
|
||||
@return The duration in milliseconds (unsigned long) of the current state.
|
||||
*/
|
||||
[[deprecated]]
|
||||
unsigned long duration() {
|
||||
return currentDuration();
|
||||
};
|
||||
|
||||
protected:
|
||||
void begin();
|
||||
virtual bool readCurrentState() =0;
|
||||
unsigned long previous_millis;
|
||||
uint16_t interval_millis;
|
||||
uint8_t state;
|
||||
unsigned long stateChangeLastTime;
|
||||
unsigned long durationOfPreviousState;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
@brief The Debouncer:Bounce class. Links the Deboucing class to a hardware pin. This class is odly named, but it will be kept that so it stays compatible with previous code.
|
||||
|
||||
*/
|
||||
class Bounce : public Debouncer
|
||||
{
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/*!
|
||||
@brief Create an instance of the Bounce class.
|
||||
|
||||
@code
|
||||
|
||||
// Create an instance of the Bounce class.
|
||||
Bounce() button;
|
||||
|
||||
@endcode
|
||||
*/
|
||||
Bounce();
|
||||
|
||||
|
||||
/*!
|
||||
@brief Attach to a pin and sets that pin's mode (INPUT, INPUT_PULLUP or OUTPUT).
|
||||
|
||||
@param pin
|
||||
The pin that is to be debounced.
|
||||
@param mode
|
||||
A valid Arduino pin mode (INPUT, INPUT_PULLUP or OUTPUT).
|
||||
*/
|
||||
void attach(int pin, int mode);
|
||||
|
||||
/**
|
||||
Attach to a pin for advanced users. Only attach the pin this way once you have previously set it up. Otherwise use attach(int pin, int mode).
|
||||
*/
|
||||
void attach(int pin);
|
||||
|
||||
Bounce(uint8_t pin, unsigned long interval_millis ) : Bounce() {
|
||||
attach(pin);
|
||||
interval(interval_millis);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@brief Return pin that this Bounce is attached to
|
||||
|
||||
@return integer identifier of the coupled pin
|
||||
*/
|
||||
inline int getPin() const {
|
||||
return this->pin;
|
||||
};
|
||||
|
||||
////////////////
|
||||
// Deprecated //
|
||||
////////////////
|
||||
|
||||
/**
|
||||
@brief Deprecated (i.e. do not use). Included for partial compatibility for programs written with Bounce version 1
|
||||
*/
|
||||
[[deprecated]]
|
||||
bool risingEdge() const { return rose(); }
|
||||
/**
|
||||
@brief Deprecated (i.e. do not use). Included for partial compatibility for programs written with Bounce version 1
|
||||
*/
|
||||
[[deprecated]]
|
||||
bool fallingEdge() const { return fell(); }
|
||||
/**
|
||||
@brief Deprecated (i.e. do not use). Included for partial compatibility for programs written with Bounce version 1
|
||||
*/
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
uint8_t pin;
|
||||
|
||||
virtual bool readCurrentState() { return digitalRead(pin); }
|
||||
virtual void setPinMode(int pin, int mode) {
|
||||
#if defined(ARDUINO_ARCH_STM32F1)
|
||||
pinMode(pin, (WiringPinMode)mode);
|
||||
#else
|
||||
pinMode(pin, mode);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
@brief The Debouncer:Bounce:Button class. The Button class matches an electrical state to a physical action.
|
||||
*/
|
||||
namespace Bounce2 {
|
||||
// code declarations
|
||||
|
||||
class Button : public Bounce{
|
||||
protected:
|
||||
bool stateForPressed = 1; //
|
||||
public:
|
||||
/*!
|
||||
@brief Create an instance of the Button class. By default, the pressed state is matched to a HIGH electrical level.
|
||||
|
||||
@code
|
||||
|
||||
// Create an instance of the Button class.
|
||||
Button() button;
|
||||
|
||||
@endcode
|
||||
*/
|
||||
Button(){ }
|
||||
|
||||
/*!
|
||||
@brief Set the electrical state (HIGH/LOW) that corresponds to a physical press. By default, the pressed state is matched to a HIGH electrical level.
|
||||
|
||||
@param state
|
||||
The electrical state (HIGH/LOW) that corresponds to a physical press.
|
||||
|
||||
*/
|
||||
void setPressedState(bool state){
|
||||
stateForPressed = state;
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief Get the electrical state (HIGH/LOW) that corresponds to a physical press.
|
||||
*/
|
||||
inline bool getPressedState() const {
|
||||
return stateForPressed;
|
||||
};
|
||||
|
||||
/*!
|
||||
@brief Returns true if the button is currently physically pressed.
|
||||
*/
|
||||
inline bool isPressed() const {
|
||||
return read() == getPressedState();
|
||||
};
|
||||
|
||||
/*!
|
||||
@brief Returns true if the button was physically pressed
|
||||
*/
|
||||
inline bool pressed() const {
|
||||
return changed() && isPressed();
|
||||
};
|
||||
|
||||
/*!
|
||||
@brief Returns true if the button was physically released
|
||||
*/
|
||||
inline bool released() const {
|
||||
return changed() && !isPressed();
|
||||
};
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user