MTcheckButton
Event management for Uno, Nano, Mega
Button like a on/off button, active when pressing on, inactive when pressing on a second time. Can call function when activation and when deactivating.
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
MTcheckButton(pin, onSelectFunction = NO_ACTION, onUnselectFunction = NO_ACTION, rest = HIGH);
- pin (uint8_t): pin to which the button is connected
- onSelectFunction: what happens when you press the button for the first time (odd
supports)
- NO_ACTION -> nothing happens
- myFunction → call a function "void myFunction(void) {...}"
- onUnselectFunction: what happens when you press the button for the second time (peer
supports)
- 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 variable
bounce
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.
Useful functions
void select(void); void unselect(void); boolean getSelect(void); virtual void onSelect(void); virtual void onUnselect(void);
select: select the button
unselect: unselect the button
getSelect: return true if the button is selected
onSelect: overload function called when pressing the button
onUnselect: overload function called when the button is unselected
Bonus functions
void setOnSelectFunction(onSelectFunction); void setOnSelectFunction(); void setOnUnselectFunction(onUnselectFunction); void setOnUnselectFunction();
setOnSelectFunction: changes the function called when pressing the button
setOnSelectFunction: without parameters removes the function called when pressing the button
setOnUnselectFunction: changes the function called when the button is unselected
setOnUnselectFunction: without parameters removes the function called when the button is unselected
Examples