MD_UISwitch Library  1.0
Library for different types of User Interface switches
MD_UISwitch_Digital Class Reference

#include <MD_UISwitch.h>

Inheritance diagram for MD_UISwitch_Digital:
Collaboration diagram for MD_UISwitch_Digital:

Public Member Functions

Class constructor and destructor.
 MD_UISwitch_Digital (uint8_t pin, uint8_t onState=KEY_ACTIVE_STATE)
 
 ~MD_UISwitch_Digital ()
 
Methods for core object control.
virtual void begin (void)
 
virtual keyResult_t read (void)
 
- Public Member Functions inherited from MD_UISwitch
 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 _pin
 pin number
 
uint8_t _onState
 digital state for ON
 
- Protected Attributes inherited from MD_UISwitch
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
 

Additional Inherited Members

- Public Types inherited from MD_UISwitch
enum  keyResult_t {
  KEY_NULL, KEY_PRESS, KEY_DPRESS, KEY_LONGPRESS,
  KEY_RPTPRESS
}
 
- Protected Types inherited from MD_UISwitch
enum  state_t {
  S_IDLE, S_DEBOUNCE1, S_DEBOUNCE2, S_PRESS,
  S_DPRESS, S_LPRESS, S_REPEAT, S_WAIT
}
 
- Protected Member Functions inherited from MD_UISwitch
keyResult_t processFSM (bool bState, bool reset=0)
 

Detailed Description

Extension class MD_UISwitch_Digital.

Implements interface for momentary ON switches, such as tact switches or microswitches.

Digital_Switches.jpg
Momentary On Digital Style Switches

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.

Constructor & Destructor Documentation

◆ MD_UISwitch_Digital()

MD_UISwitch_Digital::MD_UISwitch_Digital ( uint8_t  pin,
uint8_t  onState = KEY_ACTIVE_STATE 
)

Class Constructor.

Instantiate a new instance of the class. The parameters passed are used to the hardware interface to the switch.

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.

Parameters
pinthe digital pin to which the switch is connected.
onStatethe state for the switch to be active

◆ ~MD_UISwitch_Digital()

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.

Member Function Documentation

◆ begin()

void MD_UISwitch_Digital::begin ( void  )
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.

◆ read()

MD_UISwitch::keyResult_t MD_UISwitch_Digital::read ( void  )
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.

Returns
one of the keyResult_t enumerated values

Reimplemented from MD_UISwitch.


The documentation for this class was generated from the following files: