diff --git a/Doxyfile b/Doxyfile index e0caafb..e2f3a50 100644 --- a/Doxyfile +++ b/Doxyfile @@ -906,7 +906,7 @@ EXCLUDE_SYMBOLS = # that contain example code fragments that are included (see the \include # command). -EXAMPLE_PATH = examples/bounce/bounce.ino +EXAMPLE_PATH = examples/bounce/bounce.ino examples/change/change.ino examples/bounce_multiple/bounce_multiple.ino examples/bounce2buttons/bounce2buttons.ino # If the value of the EXAMPLE_PATH tag contains directories, you can use the # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and diff --git a/README.md b/README.md index 60ce2f5..c9546f4 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ Bounce debouncer = Bounce(); // Instantiate a Bounce object void setup() { debouncer.attach(BUTTON_PIN,INPUT_PULLUP); // Attach the debouncer to a pin with INPUT_PULLUP mode - debouncer.interval(500); + debouncer.interval(25); // Use a debounce interval of 25 milliseconds pinMode(LED_PIN,OUTPUT); // Setup the LED diff --git a/docs/_bounce2_8h_source.html b/docs/_bounce2_8h_source.html index 89bb0ea..c8928ec 100644 --- a/docs/_bounce2_8h_source.html +++ b/docs/_bounce2_8h_source.html @@ -66,16 +66,16 @@ $(function() {
Bounce2.h
-
1 /*
2  The MIT License (MIT)
3 
4  Copyright (c) 2013 thomasfredericks
5 
6  Permission is hereby granted, free of charge, to any person obtaining a copy of
7  this software and associated documentation files (the "Software"), to deal in
8  the Software without restriction, including without limitation the rights to
9  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10  the Software, and to permit persons to whom the Software is furnished to do so,
11  subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in all
14  copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23 
24 /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
25  Main code by Thomas O Fredericks (tof@t-o-f.info)
26  Previous contributions by Eric Lowry, Jim Schimpf and Tom Harkaway
27  * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
28 
29 #ifndef Bounce2_h
30 #define Bounce2_h
31 
32 #if defined(ARDUINO) && ARDUINO >= 100
33 #include "Arduino.h"
34 #else
35 #include "WProgram.h"
36 #endif
37 
38 // Uncomment the following line for "LOCK-OUT" debounce method
39 //#define BOUNCE_LOCK_OUT
40 
41 // Uncomment the following line for "BOUNCE_WITH_PROMPT_DETECTION" debounce method
42 //#define BOUNCE_WITH_PROMPT_DETECTION
43 
44 #include <inttypes.h>
45 
55 class Bounce
56 {
57  public:
58 
69  Bounce();
70 
71 
81  void attach(int pin, int mode);
82 
86  void attach(int pin);
87 
88 
96  void interval(uint16_t interval_millis);
97 
98 
107  bool update();
108 
114  bool read();
115 
119  bool fell();
120 
124  bool rose();
125 
126 
130  bool risingEdge() { return rose(); }
134  bool fallingEdge() { return fell(); }
138  Bounce(uint8_t pin, unsigned long interval_millis ) : Bounce() {
139  attach(pin);
140  interval(interval_millis);
141  }
142 
151  unsigned long duration();
152 
153 
154  // WIP HELD : unsigned long held(); // Returns the duration the previous state was held
155 
156  protected:
157  unsigned long previous_millis;
158  uint16_t interval_millis;
159  uint8_t state;
160  uint8_t pin;
161  unsigned long stateChangeLastTime;
162  // WIP HELD : unsigned long durationOfPreviousState;
163  virtual bool readCurrentState() { return digitalRead(pin); }
164  virtual void setPinMode(int pin, int mode) {
165 #if defined(ARDUINO_STM_NUCLEO_F103RB) || defined(ARDUINO_GENERIC_STM32F103C)
166  pinMode(pin, (WiringPinMode)mode);
167 #else
168  pinMode(pin, mode);
169 #endif
170  }
171 
172  private:
173  inline void changeState();
174  inline void setStateFlag(const uint8_t flag) {state |= flag;}
175  inline void unsetStateFlag(const uint8_t flag) {state &= ~flag;}
176  inline void toggleStateFlag(const uint8_t flag) {state ^= flag;}
177  inline bool getStateFlag(const uint8_t flag) {return((state & flag) != 0);}
178 };
179 
180 #endif
Definition: Bounce2.h:55
+
1 /*
2  The MIT License (MIT)
3 
4  Copyright (c) 2013 thomasfredericks
5 
6  Permission is hereby granted, free of charge, to any person obtaining a copy of
7  this software and associated documentation files (the "Software"), to deal in
8  the Software without restriction, including without limitation the rights to
9  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10  the Software, and to permit persons to whom the Software is furnished to do so,
11  subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in all
14  copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23 
24 /* * * * * * * * * * * * * * * * * * * * * * * * * * * *
25  Main code by Thomas O Fredericks (tof@t-o-f.info)
26  Previous contributions by Eric Lowry, Jim Schimpf and Tom Harkaway
27  * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
28 
29 #ifndef Bounce2_h
30 #define Bounce2_h
31 
32 #if defined(ARDUINO) && ARDUINO >= 100
33 #include "Arduino.h"
34 #else
35 #include "WProgram.h"
36 #endif
37 
38 // Uncomment the following line for "LOCK-OUT" debounce method
39 //#define BOUNCE_LOCK_OUT
40 
41 // Uncomment the following line for "BOUNCE_WITH_PROMPT_DETECTION" debounce method
42 //#define BOUNCE_WITH_PROMPT_DETECTION
43 
44 #include <inttypes.h>
45 
69 class Bounce
70 {
71  public:
72 
83  Bounce();
84 
85 
95  void attach(int pin, int mode);
96 
100  void attach(int pin);
101 
102 
110  void interval(uint16_t interval_millis);
111 
112 
121  bool update();
122 
128  bool read();
129 
133  bool fell();
134 
138  bool rose();
139 
140 
144  bool risingEdge() { return rose(); }
148  bool fallingEdge() { return fell(); }
152  Bounce(uint8_t pin, unsigned long interval_millis ) : Bounce() {
153  attach(pin);
154  interval(interval_millis);
155  }
156 
165  unsigned long duration();
166 
167 
168  // WIP HELD : unsigned long held(); // Returns the duration the previous state was held
169 
170  protected:
171  unsigned long previous_millis;
172  uint16_t interval_millis;
173  uint8_t state;
174  uint8_t pin;
175  unsigned long stateChangeLastTime;
176  // WIP HELD : unsigned long durationOfPreviousState;
177  virtual bool readCurrentState() { return digitalRead(pin); }
178  virtual void setPinMode(int pin, int mode) {
179 #if defined(ARDUINO_STM_NUCLEO_F103RB) || defined(ARDUINO_GENERIC_STM32F103C)
180  pinMode(pin, (WiringPinMode)mode);
181 #else
182  pinMode(pin, mode);
183 #endif
184  }
185 
186  private:
187  inline void changeState();
188  inline void setStateFlag(const uint8_t flag) {state |= flag;}
189  inline void unsetStateFlag(const uint8_t flag) {state &= ~flag;}
190  inline void toggleStateFlag(const uint8_t flag) {state ^= flag;}
191  inline bool getStateFlag(const uint8_t flag) {return((state & flag) != 0);}
192 };
193 
194 #endif
Definition: Bounce2.h:69
bool read()
Returns the pin&#39;s state (HIGH or LOW).
Definition: Bounce2.cpp:127
void interval(uint16_t interval_millis)
Sets the debounce interval in milliseconds.
Definition: Bounce2.cpp:36
-
bool fallingEdge()
Deprecated (i.e. do not use). Included for partial compatibility for programs written with Bounce ver...
Definition: Bounce2.h:134
+
bool fallingEdge()
Deprecated (i.e. do not use). Included for partial compatibility for programs written with Bounce ver...
Definition: Bounce2.h:148
void attach(int pin, int mode)
Attach to a pin and sets that pin&#39;s mode (INPUT, INPUT_PULLUP or OUTPUT).
Definition: Bounce2.cpp:31
bool fell()
Returns true if pin signal transitions from high to low.
Definition: Bounce2.cpp:137
bool update()
Updates the pin&#39;s state.
Definition: Bounce2.cpp:41
-
bool risingEdge()
Deprecated (i.e. do not use). Included for partial compatibility for programs written with Bounce ver...
Definition: Bounce2.h:130
+
bool risingEdge()
Deprecated (i.e. do not use). Included for partial compatibility for programs written with Bounce ver...
Definition: Bounce2.h:144
unsigned long duration()
Returns the duration in milliseconds of the current state.
Definition: Bounce2.cpp:116
-
Bounce(uint8_t pin, unsigned long interval_millis)
Deprecated (i.e. do not use). Included for partial compatibility for programs written with Bounce ver...
Definition: Bounce2.h:138
+
Bounce(uint8_t pin, unsigned long interval_millis)
Deprecated (i.e. do not use). Included for partial compatibility for programs written with Bounce ver...
Definition: Bounce2.h:152
Bounce()
Create an instance of the Bounce class.
Definition: Bounce2.cpp:11
bool rose()
Returns true if pin signal transitions from low to high.
Definition: Bounce2.cpp:132
diff --git a/docs/bounce2buttons_8ino-example.html b/docs/bounce2buttons_8ino-example.html new file mode 100644 index 0000000..1f7591d --- /dev/null +++ b/docs/bounce2buttons_8ino-example.html @@ -0,0 +1,74 @@ + + + + + + + +Bounce2: bounce2buttons.ino + + + + + + + + + +
+
+ + + + + + +
+
Bounce2 +
+
+
+ + + + + + + +
+ +
+
+ + +
+ +
+ +
+
+
bounce2buttons.ino
+
+
+

Example of two instances of the Bounce class that switches the debug LED when either one of the two buttons is pressed.

+
/*
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 );
}
}
+ + + + diff --git a/docs/bounce_8ino-example.html b/docs/bounce_8ino-example.html index 7055158..ea9dc68 100644 --- a/docs/bounce_8ino-example.html +++ b/docs/bounce_8ino-example.html @@ -62,7 +62,7 @@ $(function() {
bounce.ino
-

This is an example of how to use the Example_Test class. More details about this example.

+

Simple example of the Bounce library that switches the debug LED when a button is pressed.

/*
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 );
}
}