Commanders
Arduino buttons/bus library
ButtonsCommanderSwitchOnePin.cpp
1 /*************************************************************
2 project: <Commanders>
3 author: <Thierry PARIS>
4 description: <Switch button with one pin only with debounce.>
5 *************************************************************/
6 
7 #include <Commanders.h>
8 #ifndef NO_BUTTONSCOMMANDER
9 #ifndef NO_BUTTONSCOMMANDERSWITCH
10 
12 {
13  this->debounceDelay = 50;
14  this->lastButtonState = HIGH;
15  this->lastDebounceTime = 0;
16 }
17 
18 void ButtonsCommanderSwitchOnePin::begin(unsigned long inId, int inPin)
19 {
20  this->Pin = Arduino_to_GPIO_pin(inPin);
21  this->Id = inId;
22 
23  pinMode2f(this->Pin, INPUT_PULLUP);
24 }
25 
27 {
28  if (this->Pin != DP_INVALID)
29  {
30  // Initialize first switch state at start
31  this->lastButtonState = digitalRead2f(this->Pin);
32 
34  }
35 }
36 
38 {
39  return ButtonsCommanderSwitch::loopOnePin(this->Id, this->Pin, this->Id, this->debounceDelay, &this->lastButtonState, &this->lastDebounceTime);
40 }
41 
42 #ifdef COMMANDERS_PRINT_COMMANDERS
43 void ButtonsCommanderSwitchOnePin::printCommander()
44 {
45  Serial.print(F(" SwitchOnePin Pin: "));
46  Serial.print(GPIO_to_Arduino_pin(this->Pin));
47  Serial.print(F(" / Id: "));
48  Serial.print(this->Id);
49  Serial.print(F(" / Debounce delay: "));
50  Serial.print(this->debounceDelay);
51  Serial.println(F(""));
52 }
53 #endif
54 #endif
55 #endif
static unsigned long loopOnePin(unsigned long inId, GPIO_pin_t inPin, unsigned long inPreviousId, unsigned long inDebounceDelay, byte *inpLastPinState, unsigned long *inpLastDebounceTime, bool inSendEvent = true)
static unsigned long RaiseEvent(unsigned long inId, COMMANDERS_EVENT_TYPE inEvent = COMMANDERS_EVENT_MOVEPOSITIONID, int inData = 0)
Definition: Commanders.cpp:27
void begin(unsigned long inId, int inPin)
#define UNDEFINED_ID
Definition: Events.h:38