93 int16_t
begin(uint8_t
pin, uint16_t debounce_mS = 30,
bool invert =
true,
bool usePullUp =
true)
110 return (
_sw.readPublicData(
_pin) > 0);
123 uint8_t tx[8] = { 201,
_pin,
_pinMode,1,0x55,0x55,0x55,0x55 };
125 _sw.sendPacket(tx,rx);
134 return(256 * rx[7] + rx[6]);
148 uint8_t tx[8] = { 201,
_pin,
_pinMode,1,0x55,0x55,0x55,0x55 };
150 _sw.sendPacket(tx, rx);
160 return(256 * rx[7] + rx[6]);
175 uint8_t tx[8] = { 201,
_pin,
_pinMode,(uint8_t)resetTransitionCounts,0x55,0x55,0x55,0x55 };
177 _sw.sendPacket(tx, rx);
215 _debouncedInput = serialWombatDebouncedInput;
231 void begin(
long* variableToIncrement,
232 long slowIncrement = 1,
unsigned long slow_mS_betweenIncrements = 250,
233 uint16_t slowToMediumTransition_mS = 1000,
234 long mediumIncrement = 1,
unsigned long medium_mS_betweenIncrements = 100,
235 uint16_t mediumToFastTransition_mS = 1000 ,
236 long fastIncrement = 1,
unsigned long fast_mS_betweenIncrements = 50)
238 _variableToIncrement = variableToIncrement;
240 _slowIncrement = slowIncrement;
241 _slow_mS_betweenIncrements = slow_mS_betweenIncrements;
243 _slowToMediumTransition_mS = slowToMediumTransition_mS;
245 _mediumIncrement = mediumIncrement;
246 _medium_mS_betweenIncrements = medium_mS_betweenIncrements;
248 _mediumToFastTransistion_mS = mediumToFastTransition_mS;
250 _fastIncrement = fastIncrement;
251 _fast_mS_betweenIncrements = fast_mS_betweenIncrements;
253 _lastPressDuration = 0;
259 uint16_t pressDuration = _debouncedInput.readDurationInTrueState_mS();
261 bool incremented =
false;
262 bool pressed =
false;
263 if (pressDuration > 0)
265 if (_lastPressDuration >= pressDuration)
267 _lastPressDuration = 0;
270 if (pressDuration > _mediumToFastTransistion_mS)
273 increments = (pressDuration - _lastPressDuration) / _fast_mS_betweenIncrements;
274 *_variableToIncrement += _fastIncrement * increments;
275 _lastPressDuration += _fast_mS_betweenIncrements * increments;
277 else if (pressDuration > _slowToMediumTransition_mS)
280 increments = (pressDuration - _lastPressDuration) / _medium_mS_betweenIncrements;
281 *_variableToIncrement += _mediumIncrement * increments;
282 _lastPressDuration += _medium_mS_betweenIncrements * increments;
287 increments = (pressDuration - _lastPressDuration) / _slow_mS_betweenIncrements;
288 *_variableToIncrement += _slowIncrement * increments;
289 _lastPressDuration += _slow_mS_betweenIncrements * increments;
290 incremented = increments > 0;
294 _debouncedInput.transitions = 0;
301 _lastPressDuration = 0;
302 int presses = _debouncedInput.transitions / 2;
303 *_variableToIncrement += _slowIncrement * presses;
304 _debouncedInput.transitions -= presses * 2;
311 if (*_variableToIncrement <
lowLimit)
326 long* _variableToIncrement;
329 unsigned long _slow_mS_betweenIncrements;
331 uint16_t _slowToMediumTransition_mS;
333 long _mediumIncrement;
334 unsigned long _medium_mS_betweenIncrements;
336 uint16_t _mediumToFastTransistion_mS;
339 unsigned long _fast_mS_betweenIncrements;
341 unsigned long _lastPressDuration;
Class for a Serial Wombat chip. Each Serial Wombat chip on a project should have its own instance.
SerialWombat18CapTouch, SerialWombatDebouncedInput and SerialWombatMatrixButton inherit from this cla...
uint16_t transitions
Number of transitions returned by last call to readTransitionsState()
SerialWombatAbstractButton()
bool digitalRead()
Returns the debounced state of the input.
bool readTransitionsState(bool resetTransitionCounts=true)
Queries the number of transistions that have occured on the debounced input.
int16_t begin(uint8_t pin, uint16_t debounce_mS=30, bool invert=true, bool usePullUp=true)
Initialize a debounced input.
uint16_t readDurationInTrueState_mS()
return the number of mS that the input has been in true state
uint16_t readDurationInFalseState_mS()
return the number of mS that the input has been in false state
SerialWombatDebouncedInput(SerialWombatChip &serialWombatChip)
Constructor for the SerialWombatDebouncedInput class.
SerialWombatButtonCounter(SerialWombatAbstractButton &serialWombatDebouncedInput)
Constructor for SerialWombatButtonCounter.
bool update()
Called periodically to query the SerialWombatDebouncedInput and update the variable.
long highLimit
The variable will not increment above this limit.
long lowLimit
The variable will not decrement below this limit.
void begin(long *variableToIncrement, long slowIncrement=1, unsigned long slow_mS_betweenIncrements=250, uint16_t slowToMediumTransition_mS=1000, long mediumIncrement=1, unsigned long medium_mS_betweenIncrements=100, uint16_t mediumToFastTransition_mS=1000, long fastIncrement=1, unsigned long fast_mS_betweenIncrements=50)
SerialWombatPin(SerialWombatChip &serialWombatChip)
Instantiates a Serial Wombat Pin.
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)
uint8_t pin()
Returns the current SW pin number. Used primarily for virtual calls by derived classes.