![]() |
MD_UISwitch Library
1.2
Library for different types of User Interface switches
|
#include <MD_UISwitch.h>
Public Member Functions | |
Class constructor and destructor. | |
MD_UISwitch_Digital (uint8_t pin, uint8_t onState=KEY_ACTIVE_STATE) | |
MD_UISwitch_Digital (uint8_t *pins, uint8_t pinCount, uint8_t onState=KEY_ACTIVE_STATE) | |
~MD_UISwitch_Digital () | |
Methods for core object control. | |
virtual void | begin (void) |
virtual keyResult_t | read (void) |
![]() | |
MD_UISwitch (void) | |
~MD_UISwitch () | |
virtual uint8_t | getKey (void) |
void | setDebounceTime (uint16_t t) |
void | setDoublePressTime (uint16_t t) |
void | setLongPressTime (uint16_t t) |
void | setRepeatTime (uint16_t t) |
void | enableDoublePress (boolean f) |
void | enableLongPress (boolean f) |
void | enableRepeat (boolean f) |
void | enableRepeatResult (boolean f) |
Protected Attributes | |
uint8_t | _pinSimple |
pin number for simple pins | |
uint8_t * | _pins |
pointer to data for one or more pins | |
uint8_t | _pinCount |
number of pins defined | |
uint8_t | _onState |
digital state for ON | |
![]() | |
state_t | _state |
the FSM current state | |
uint32_t | _timeActive |
the millis() time it was last activated | |
uint8_t | _enableFlags |
functions enabled/disabled | |
uint16_t | _timeDebounce |
debounce time in milliseconds | |
uint16_t | _timeDoublePress |
double press detection time in milliseconds | |
uint16_t | _timeLongPress |
long press time in milliseconds | |
int16_t | _timeRepeat |
repeat time delay in milliseconds | |
uint8_t | _lastKey |
persists the last key value until a new one is detected | |
int16_t | _lastKeyIdx |
internal index of the last key read | |
Additional Inherited Members | |
![]() | |
enum | keyResult_t { KEY_NULL, KEY_PRESS, KEY_DPRESS, KEY_LONGPRESS, KEY_RPTPRESS } |
![]() | |
enum | state_t { S_IDLE, S_DEBOUNCE1, S_DEBOUNCE2, S_PRESS, S_DPRESS, S_LPRESS, S_REPEAT, S_WAIT } |
![]() | |
keyResult_t | processFSM (bool bState, bool reset=0) |
Extension class MD_UISwitch_Digital.
Implements interface for momentary ON switches, such as tact switches or microswitches.
Switches can be wired as pull-up or pull-down. Pull-up switches are initialised with the internal pull-up enabled. Pull-down switches require an external pull-down resistor circuit. How the switch type is initialised depends on the parameters passed to the class constructor.
MD_UISwitch_Digital::MD_UISwitch_Digital | ( | uint8_t | pin, |
uint8_t | onState = KEY_ACTIVE_STATE |
||
) |
Class Constructor - simple pin.
Instantiate a new instance of the class. The parameters passed are used to the hardware interface to the switch.
This form of the constructor is for a simple digital pin (ie, one digital pin).
The option parameter onState tells the library which level (LOW or HIGH) should be considered the switch 'on' state. If the default LOW state is selected then the library will initialise the pin with INPUT_PULLUP and no external pullup resistors are necessary. If specified HIGH, external pull down resistors will be required.
pin | the digital pin to which the switch is connected. |
onState | the state for the switch to be active |
MD_UISwitch_Digital::MD_UISwitch_Digital | ( | uint8_t * | pins, |
uint8_t | pinCount, | ||
uint8_t | onState = KEY_ACTIVE_STATE |
||
) |
Class Constructor - array of pins.
Instantiate a new instance of the class. The parameters passed are used to the hardware interface to the switch.
This form of the constructor is for an array of digital pins. The data is not copied from the user code, so the array elements need to remain in scope and constant for the life of the object.
The option parameter onState tells the library which level (LOW or HIGH) should be considered the switch 'on' state. If the default LOW state is selected then the library will initialise each pin with INPUT_PULLUP and no external pullup resistors are necessary. If specified HIGH, external pull down resistors will be required.
pins | pointer to array of pin numbers to which the switches are connected. |
pinCount | the number of pin in the pins[] array |
onState | the state for the switch to be active |
MD_UISwitch_Digital::~MD_UISwitch_Digital | ( | ) |
Class Destructor.
Release allocated memory and does the necessary to clean up once the queue is no longer required.
|
virtual |
Initialize the object.
Initialise the object data. This needs to be called during setup() to initialise new data for the class that cannot be done during the object creation.
Reimplemented from MD_UISwitch.
|
virtual |
Return the state of the switch
Return one of the keypress types depending on what has been detected. The timing for each keypress starts when the first transition of the switch from inactive to active state and is recognised by a finite state machine whose operation is directed by the timer and option values specified.
Reimplemented from MD_UISwitch.