Serial Wombat Arduino Library
SerialWombatDebouncedInput.h
Go to the documentation of this file.
1 #pragma once
2 /*
3 Copyright 2020-2021 Broadwell Consulting Inc.
4 
5 "Serial Wombat" is a registered trademark of Broadwell Consulting Inc. in
6 the United States. See SerialWombat.com for usage guidance.
7 
8 Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14 
15 The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17 
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24  * OTHER DEALINGS IN THE SOFTWARE.
25 */
26 
27 #include "SerialWombat.h"
28 #include "limits.h"
29 
75 {
76 public:
81 
88  void begin(uint8_t pin);
89 
96  void begin(uint8_t pin, uint16_t debounce_mS, bool invert, bool usePullUp);
97 
104  bool digitalRead();
105 
111  uint16_t readDurationInTrueState_mS();
117  uint16_t readDurationInFalseState_mS();
118 
126  bool readTransitionsState();
127 
128 private:
129  uint8_t _pin = 255;
130 };
131 
132 
153 {
154 public:
155 
158  SerialWombatButtonCounter( SerialWombatAbstractButton& serialWombatDebouncedInput);
159 
171  void begin(long* variableToIncrement,
172  long slowIncrement = 1, unsigned long slow_mS_betweenIncrements = 250,
173  uint16_t slowToMediumTransition_mS = 1000,
174  long mediumIncrement = 1, unsigned long medium_mS_betweenIncrements = 100,
175  uint16_t mediumToFastTransition_mS = 1000 ,
176  long fastIncrement = 1, unsigned long fast_mS_betweenIncrements = 50);
178  bool update();
179 
181  long highLimit = LONG_MAX;
183  long lowLimit = LONG_MIN;
184 
185 private:
186  SerialWombatAbstractButton& _debouncedInput;
187  long* _variableToIncrement;
188 
189  long _slowIncrement;
190  unsigned long _slow_mS_betweenIncrements;
191 
192  uint16_t _slowToMediumTransition_mS;
193 
194  long _mediumIncrement;
195  unsigned long _medium_mS_betweenIncrements;
196 
197  uint16_t _mediumToFastTransistion_mS;
198 
199  long _fastIncrement;
200  unsigned long _fast_mS_betweenIncrements;
201 
202  unsigned long _lastPressDuration;
203 
204 };
205 
SerialWombatChip
Class for a Serial Wombat chip. Each Serial Wombat chip on a project should have its own instance.
Definition: SerialWombat.h:267
SerialWombatButtonCounter::update
bool update()
Called periodically to query the SerialWombatDebouncedInput and update the variable.
Definition: SerialWombatDebouncedInput.cpp:97
SerialWombatButtonCounter::begin
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)
Definition: SerialWombatDebouncedInput.cpp:76
SerialWombatButtonCounter
A class that runs on top of SerialWombaAbstractButton to increment or decrement a variable based on a...
Definition: SerialWombatDebouncedInput.h:152
SerialWombatDebouncedInput::readDurationInTrueState_mS
uint16_t readDurationInTrueState_mS()
return the number of mS that the debounced input has been in true state
Definition: SerialWombatDebouncedInput.cpp:25
SerialWombatButtonCounter::lowLimit
long lowLimit
The variable will not decrement below this limit.
Definition: SerialWombatDebouncedInput.h:183
SerialWombat.h
SerialWombatDebouncedInput::begin
void begin(uint8_t pin)
Initialize a debounced input (simplified for typical switch to ground)
Definition: SerialWombatDebouncedInput.cpp:7
SerialWombatDebouncedInput
A pin mode class that debounces inputs.
Definition: SerialWombatDebouncedInput.h:74
SerialWombatPin
Describes a Serial Wombat Pin. Is base class for other pin modes.
Definition: SerialWombat.h:727
SerialWombatButtonCounter::highLimit
long highLimit
The variable will not increment above this limit.
Definition: SerialWombatDebouncedInput.h:181
SerialWombatDebouncedInput::readTransitionsState
bool readTransitionsState()
Queries the number of transistions that have occured on the debounced input.
Definition: SerialWombatDebouncedInput.cpp:62
SerialWombatPin::pin
uint8_t pin()
Returns the current SW pin number. Used primarily for virtual calls by derived classes.
Definition: SerialWombat.h:789
SerialWombatDebouncedInput::digitalRead
bool digitalRead()
Returns the debounced state of the input.
Definition: SerialWombatDebouncedInput.cpp:19
SerialWombatDebouncedInput::readDurationInFalseState_mS
uint16_t readDurationInFalseState_mS()
return the number of mS that the debounced input has been in false state
Definition: SerialWombatDebouncedInput.cpp:43
SerialWombatDebouncedInput::SerialWombatDebouncedInput
SerialWombatDebouncedInput(SerialWombatChip &serialWombatChip)
Constructor for the SerialWombatDebouncedInput class.
Definition: SerialWombatDebouncedInput.cpp:4
SerialWombatButtonCounter::SerialWombatButtonCounter
SerialWombatButtonCounter(SerialWombatAbstractButton &serialWombatDebouncedInput)
Constructor for SerialWombatButtonCounter.
Definition: SerialWombatDebouncedInput.cpp:71
SerialWombatAbstractButton
SerialWombat18CapTouch, SerialWombatDebouncedInput and SerialWombatMatrixButton inherit from this cla...
Definition: SerialWombatAbstractButton.h:38