MTbutton, push button
Event management for Uno, Nano, Mega
Type button bell, active if you press it, inactive when it is released. Can call functions during support and when relaxing.
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
MTbutton(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
- NO_ACTION → nothing happens
- myFunction → call a function "void myFunction(void) {...}"
- onUnselectFunction: what happens when you release 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 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
boolean getSelect(void); virtual void onSelect(void); virtual void onUnselect(void);
getSelect: return true if the button is pushed
onSelect: overload function called when pressing the button
onUnselect: overload function called when releasing the button
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 during releasing the button
setOnUnselectFunction: without parameters removes the function called when releasing the button
Examples
- Light a LED on a press button
- Send the letter A on a press button
- Send letters on press buttons
- Timer