Serial Wombat Arduino Library
|
A pin mode class that debounces inputs. More...
#include <SerialWombatDebouncedInput.h>
Public Member Functions | |
SerialWombatDebouncedInput (SerialWombatChip &serialWombatChip) | |
Constructor for the SerialWombatDebouncedInput class. More... | |
int16_t | begin (uint8_t pin, uint16_t debounce_mS=30, bool invert=true, bool usePullUp=true) |
Initialize a debounced input. More... | |
bool | digitalRead () |
Returns the debounced state of the input. More... | |
uint16_t | readDurationInTrueState_mS () |
return the number of mS that the input has been in true state More... | |
uint16_t | readDurationInFalseState_mS () |
return the number of mS that the input has been in false state More... | |
bool | readTransitionsState (bool resetTransitionCounts=true) |
Queries the number of transistions that have occured on the debounced input. More... | |
Public Member Functions inherited from SerialWombatAbstractButton | |
SerialWombatAbstractButton () | |
Public Member Functions inherited from SerialWombatPin | |
SerialWombatPin (SerialWombatChip &serialWombatChip) | |
Instantiates a Serial Wombat Pin. More... | |
SerialWombatPin (SerialWombatChip &serialWombatChip, uint8_t pin) | |
Instantiates a Serial Wombat Pin. More... | |
uint16_t | readPublicData () |
Read the 16 Bit public data associated with this pin. More... | |
void | pinMode (uint8_t mode, bool pullDown=false, bool openDrain=false) |
Set pin to INPUT or OUTPUT, with options for pull Ups and open Drain settings. More... | |
void | digitalWrite (uint8_t val) |
Set output pin High or Low. More... | |
int | digitalRead () |
Reads the state of the Pin. More... | |
uint16_t | writePublicData (uint16_t value) |
Write a 16 bit value to this pin. More... | |
uint8_t | pin () |
Returns the current SW pin number. Used primarily for virtual calls by derived classes. More... | |
uint8_t | swPinModeNumber () |
Returns the Mode number. Used primarily by derived classes to populate packet data. More... | |
int16_t | initPacketNoResponse (uint8_t packetNumber, uint8_t param0=0x55, uint8_t param1=0x55, uint8_t param2=0x55, uint8_t param3=0x55, uint8_t param4=0x55) |
int16_t | initPacketNoResponse (uint8_t packetNumber, uint16_t param0=0x55, uint8_t param1=0x55, uint8_t param2=0x55, uint8_t param3=0x55) |
int16_t | initPacketNoResponse (uint8_t packetNumber, uint16_t param0, uint16_t param1, uint8_t param2=0x55) |
int16_t | disable () |
Disables the pin mode (if applicable) More... | |
Additional Inherited Members | |
Public Attributes inherited from SerialWombatAbstractButton | |
uint16_t | transitions = 0 |
Number of transitions returned by last call to readTransitionsState() More... | |
Protected Attributes inherited from SerialWombatPin | |
uint8_t | _pin = 255 |
SerialWombatChip & | _sw |
uint8_t | _pinMode = 0 |
A pin mode class that debounces inputs.
The SerialWombatDebouncedInput class is used to debounce inputs such as switches.
See the example sw4b_ard_Debounce1 distributed with the Serial Wombat Arduino Library for an example.
Video Tutorial
One SerialWombatDebouncedInput instance should be declared per debounced input.
The class sends commands and reads data from the Serial Wombat. The actual switch debouncing algorithm runs on the Serial Wombat.
The Serial Wombat's firmware algorithm polls the input every 1mS. After it has been different from the reported value for X consecutive mS, the reported value changes to the new polled value. The number of mS required for a change can be configured.
The Debounced Input mode keeps track of how long the debounced result has been in the current state (up to 65535 mS) and can report this to the host. This is useful for implementing user interfaces that react based on how long a button has been held.
The Debounced Input mode keeps track of how many transitions have occured. This can be used to poll the Debounced Input infrequently for status, but still process all button presses/releases that occured since the last poll.
The pin mode has weak pull-up circuitry availble, and the ability to report inverted values. These are both enabled when the simpliest begin() call is used, allowing buttons that switch the Serial Wombat pin to ground to be used without additional hardware.
See also the SerialWombatButtonCounter class which can run on top of this one.
|
inline |
Constructor for the SerialWombatDebouncedInput class.
serialWombat | a reference to the Serial Wombat on which the Debounced Input will exist |
|
inline |
Initialize a debounced input.
pin | The Serial Wombat pin used for the debounced input |
debounce_mS | number of mS the pin must be stable to cause a transition |
invert | FALSE: pin reading is returned TRUE: inverted pin reading is returned |
usePullUp | Whether the pin's weak pull up is enabled |
|
inlinevirtual |
Returns the debounced state of the input.
This function reads from the public data of the pin which indicates the debounced and invert adjusted state of the input
Implements SerialWombatAbstractButton.
|
inlinevirtual |
return the number of mS that the input has been in false state
Note that this value starts incrementing after any debounce period, not after the physical pin transition.
Implements SerialWombatAbstractButton.
|
inlinevirtual |
return the number of mS that the input has been in true state
Note that this value starts incrementing after the debounce period, not after the physical pin transition.
Implements SerialWombatAbstractButton.
|
inlinevirtual |
Queries the number of transistions that have occured on the debounced input.
This function queries the debounced input for current state and transitions since last call. transition count is put in the global member transitions. The debounced input in the Serial Wombat resets its count to zero after this call.
Implements SerialWombatAbstractButton.