MTdoubleButton,
like a mouse
Event management for Uno, Nano, Mega
Button like a mouse button. Can call functions during a single click and during a double click..
Include to add
#include <MTobjects.h> // See http://arduino.dansetrad.fr/en/MTobjects
I strongly advise to leave the comment, if another person wanted to try the program, they would have a download link directly. This is valid for all the libraries you use.
Useful comment
if_not_pressed
This comment is a word that can be added anywhere and which is ignored by the compiler.
Constructor
MTdoubleButton(pin, onDoubleSelectFunction = NO_ACTION, onSelectFunction = NO_ACTION, rest = HIGH);
- pin (uint8_t): pin to which the button is connected
- onDoubleSelectFunction: what happens when you double click the button
- NO_ACTION -> nothing happens
- myFunction → call a function "void myFunction(void) {...}"
- onSelectFunction: what happens when you simple click the button
- NO_ACTION -> nothing happens
- myFunction → call a function "void myFunction(void) {...}"
- rest (boolean): pin state if the button is release
- HIGH -> if it is wired between GND and pin (recommended). The pullup resistor is automatically added
- LOW -> if it is wired between VCC and pin, with a pulldown resistance between pin and GND
Useful variables
bounce doubleBounce
bounce (word): time during which rebounds are ignored. By default 32ms, rounded up to packages of 16ms upper. f.ex. BOUNCE
= 50 milli_seconds; gives 64ms maximum rebounds.
doubleBounce (word): time during which we wait a doble click. By default 256ms, rounded
up to packages of 16ms upper.
Please note: taking into account a single click is delayed: at the first click, we do not yet know if there will be a second or not. In the event of a simple click, you have to wait a doubleBounce time to find out. The simple click is therefore detected with this late time.
Useful functions
boolean getSelect(void); virtual void onDoubleSelect(void); virtual void onSelect(void);
getSelect: return true if the button is pushed
onDoubleSelect: overload function called when double pressing the button
onSelect: overload function called when pressing the button
Bonus functions
void setDoubleSelectFunction(onUnselectFunction); void setDoubleSelectFunction(); void setOnSelectFunction(onSelectFunction); void setOnSelectFunction();
setDoubleSelectFunction: changes the function called when double pressing the button
setDoubleSelectFunction: without parameters removes the function called when double pressing the button
setOnSelectFunction: changes the function called when simple pressing the button
setOnSelectFunction: without parameters removes the function called when simple pressing the button
Examples