![]() |
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_4017KM (uint8_t numKeys, uint8_t pinClk, uint8_t pinKey, uint8_t pinRst) | |
~MD_UISwitch_4017KM () | |
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 Member Functions | |
void | reset (void) |
reset the 4017 IC | |
void | clock (void) |
clock the 4017 IC | |
![]() | |
keyResult_t | processFSM (bool bState, bool reset=0) |
Protected Attributes | |
uint8_t | _numKeys |
total number of keys | |
uint8_t | _pinClk |
4017 clock pin, LOW to HIGH transition | |
uint8_t | _pinRst |
4017 reset pin (0 if not used), LOW to HIGH transition | |
uint8_t | _pinKey |
key switch output to Arduino, HIGH means key is pressed | |
![]() | |
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 } |
Extension class MD_UISwitch_4017KM.
Implements keyboard matrix switches implemented using 4017 decade counter (see https://arduinoplusplus.wordpress.com/2016/02/17/up-to-100-switches-with-3-digital-pins/).
Using a 4017 IC, this class implements a method for reading many open/closed switches using only three digital I/O pins (Clock, Reset and DataIn). The class will scan a key matrix that have circuits similar to that shown above. Pin numbers used are passed to the class constructor allow the code to manage the 4017 IC to determine which key has been pressed. Pins should be directly connected to the matrix without pull-up or pull-down resistors.
The class will only detect a key if there is just one key pressed. If more than one key is pressed it will pause until just one key remains pressed.
MD_UISwitch_4017KM::MD_UISwitch_4017KM | ( | uint8_t | numKeys, |
uint8_t | pinClk, | ||
uint8_t | pinKey, | ||
uint8_t | pinRst | ||
) |
Class Constructor.
Instantiate a new instance of the class. The parameters passed are used to the hardware interface to the switch.
The class will only return a valid key if just one key is pressed. If more than one key is pressed simultaneously, all the keys are ignored until just a single key is again detected.
numKeys | the number of keys in the 4017 matrix (rows*columns). |
pinClk | pin number for the 4017 clock pin, LOW to HIGH transition. |
pinRst | pin number for the 4017 reset pin (0 if not used), LOW to HIGH transition. |
pinKey | pin number for the key switch output to Arduino, HIGH means key is pressed. |
MD_UISwitch_4017KM::~MD_UISwitch_4017KM | ( | ) |
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 key pressed of the switch matrix
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.