Engduino  3.1.0
A fun device for learning coding
EngduinoButton.h
Go to the documentation of this file.
1 
14 #ifndef __ENGDUINOBUTTON_H__
15 #define __ENGDUINOBUTTON_H__
16 
17 #include <Arduino.h>
18 #include <Engduino.h>
19 
20 #define DEBOUNCE_DELAY 50
21 
22 // Needed to ensure correct linkage between C++ and C linkage of ISR
23 extern "C" void INT6_vect(void) __attribute__ ((signal));
24 
26 {
27  private:
28  /*
29  * Timings on this need to be stored as longs, simply because millis(),
30  * which we use for timing, returns a long and we would otherwise encounter
31  * problems with wrapping
32  */
33  volatile long lastChangeTime; // The last time the button input changed
34  volatile bool buttonState; // Whether the button is currently pressed
35  volatile bool fallingEdge; // Whether we're looking for a falling or rising edge in the ISR
36  volatile bool wasPressedState; // Whether the button has been pressed since we last checked
37  volatile bool wasReleasedState; // Whether the button has been released since we last checked
38  long debounceDelayTime; // How long we will wait until saying the switch is settled
39 
40  public:
41  EngduinoButtonClass();
42  void begin(long debounceDelay=DEBOUNCE_DELAY);
43  void end();
44  void reset();
45 
46  bool isPressed();
47  void waitUntilPressed();
48  void waitUntilReleased();
49  bool wasPressed();
50  bool wasReleased();
51 
52  /*
53  * The ISR needs access to the private variables, so we declare it
54  * a friend of the class
55  */
56  friend void INT6_vect();
57 };
58 
59 extern EngduinoButtonClass EngduinoButton;
60 
61 #endif
62 
Definition: EngduinoButton.h:25