8 #ifndef NO_BUTTONSCOMMANDER 9 #ifndef NO_BUTTONSCOMMANDERANALOGPUSHES 14 this->lastButtonState = 10000;
16 this->lastDebounceTime = 0;
17 this->debounceDelay = 50;
24 this->size = inNumberOfItems;
27 digitalWrite(inButtonPin, HIGH);
28 this->analogPin = inButtonPin;
29 this->readingTolerancy = inTolerancy;
31 for (
int i = 0; i < this->size; i++)
33 #ifdef COMMANDERS_DEBUG_MODE 34 if (inpButtonValues[i] < 0 || inpButtonValues[i] > ANALOG_LIMIT)
36 Serial.print(F(
"Analog push buttons. Invalid value "));
37 Serial.print(inpButtonValues[i]);
38 Serial.print(F(
" for button "));
40 Serial.print(F(
". Value must be between 0 and "));
41 Serial.print(ANALOG_LIMIT);
42 Serial.print(F(
" !"));
45 this->pButtons[i].
begin(inpIds[i], inpButtonValues[i], inTolerancy);
48 this->lastButtonState = 10000;
49 this->lastDebounceTime = 0;
51 pinMode(this->analogPin, INPUT);
57 for (
int i = 0; i < this->size; i++)
58 if (this->pButtons[i].
GetId() == inId)
59 return &(this->pButtons[i]);
68 if (this->analogPin == 0)
72 int reading = analogRead(this->analogPin);
74 #ifdef COMMANDERS_DEBUG_VERBOSE_MODE 75 Serial.print(F(
"Analog push button value "));
76 Serial.println(reading);
84 if (this->lastDebounceTime == 0 && (reading < this->lastButtonState - this->readingTolerancy || reading > this->lastButtonState + this->readingTolerancy))
87 this->lastDebounceTime = millis();
88 this->lastButtonState = reading;
91 if (this->lastDebounceTime > 0 && (millis() - this->lastDebounceTime) > this->debounceDelay)
97 if (reading >= this->lastButtonState - this->readingTolerancy && reading <= this->lastButtonState + this->readingTolerancy)
99 for (
int i = 0; i < this->size; i++)
100 if (this->pButtons[i].IsPushed(reading))
102 foundID = this->pButtons[i].
GetId();
104 #ifdef COMMANDERS_DEBUG_MODE 105 Serial.print(F(
"Analog push button "));
107 Serial.println(F(
" pressed"));
112 this->lastDebounceTime = 0;
113 this->lastButtonState = reading;
121 this->lastButtonPressed = -1;
124 #ifdef COMMANDERS_PRINT_COMMANDERS 125 void ButtonsCommanderAnalogPushes::printCommander()
127 Serial.print(F(
" AnalogPushes - Pin :"));
128 Serial.print(this->analogPin);
129 Serial.print(F(
" / Reading Accuracy: "));
130 Serial.print(this->readingTolerancy);
131 Serial.print(F(
" / Debounce delay: "));
132 Serial.println(this->debounceDelay);
134 for (
int i = 0; i < this->size; i++)
136 Serial.print(F(
" "));
137 this->
GetItem(i)->printCommander();
static unsigned long RaiseEvent(unsigned long inId, COMMANDERS_EVENT_TYPE inEvent = COMMANDERS_EVENT_MOVEPOSITIONID, int inData = 0)