Engduino v1.0
EngduinoButton.h
Go to the documentation of this file.
00001 /**
00002 * \defgroup EngduinoButton Driver for the Engduino Button
00003 * 
00004 * @{
00005 */
00006 
00007 /**
00008 * \file 
00009 *               Engduino Button driver
00010 * \author
00011 *               Engduino team: support@engduino.org
00012 */
00013 
00014 #ifndef __ENGDUINOBUTTON_H__
00015 #define __ENGDUINOBUTTON_H__
00016 
00017 #include <Arduino.h>
00018 #include <Engduino.h>
00019 
00020 #define DEBOUNCE_DELAY 50
00021 
00022 // Needed to ensure correct linkage between C++ and C linkage of ISR
00023 extern "C" void INT6_vect(void) __attribute__ ((signal));
00024 
00025 class EngduinoButtonClass 
00026 {
00027         private:
00028                 /*
00029                  * Timings on this need to be stored as longs, simply because millis(),
00030                  * which we use for timing, returns a long and we would otherwise encounter
00031                  * problems with wrapping
00032                  */
00033                 volatile long lastChangeTime;   // The last time the button input changed
00034                 volatile bool buttonState;              // Whether the button is currently pressed
00035                 volatile bool fallingEdge;              // Whether we're looking for a falling or rising edge in the ISR
00036                 volatile bool wasPressedState;  // Whether the button has been pressed since we last checked
00037                 volatile bool wasReleasedState; // Whether the button has been released since we last checked
00038                 long debounceDelayTime;                 // How long we will wait until saying the switch is settled
00039 
00040         public:
00041                 EngduinoButtonClass();
00042                 void begin(long debounceDelay=DEBOUNCE_DELAY);
00043                 void end();
00044                 void reset();
00045 
00046                 bool isPressed();
00047                 void waitUntilPressed();
00048                 void waitUntilReleased();
00049                 bool wasPressed();
00050                 bool wasReleased();
00051 
00052                 /*
00053                  * The ISR needs access to the private variables, so we declare it
00054                  * a friend of the class
00055                  */
00056                 friend void INT6_vect();
00057 };
00058 
00059 extern EngduinoButtonClass EngduinoButton;
00060 
00061 #endif
00062 
00063 /** @} */