8 #ifndef NO_BUTTONSCOMMANDER 9 #ifndef NO_BUTTONSCOMMANDERANALOGPUSHES 14 this->lastButtonState = LOW;
16 this->lastDebounceTime = 0;
17 this->debounceDelay = 50;
24 this->size = inNumberOfItems;
27 this->analogPin = inButtonPin;
28 this->readingTolerancy = inTolerancy;
30 for (
int i = 0; i < this->size; i++)
32 #ifdef COMMANDERS_DEBUG_MODE 33 if (inpButtonValues[i] < 0 || inpButtonValues[i] > 1023)
35 Serial.print(F(
"Analog push buttons. Invalid value "));
36 Serial.print(inpButtonValues[i]);
37 Serial.print(F(
" for button "));
39 Serial.println(F(
". Value must between 0 and 1023 !"));
42 this->pButtons[i].
begin(inpIds[i], inpButtonValues[i], inTolerancy);
45 pinMode(this->analogPin, INPUT);
50 for (
int i = 0; i < this->size; i++)
51 if (this->pButtons[i].
GetId() == inId)
52 return &(this->pButtons[i]);
61 if (this->analogPin == 0)
65 int reading = analogRead(this->analogPin);
72 if (this->lastDebounceTime == 0 && (reading < this->lastButtonState - this->readingTolerancy || reading > this->lastButtonState + this->readingTolerancy))
75 this->lastDebounceTime = millis();
78 if (this->lastDebounceTime > 0 && (millis() - this->lastDebounceTime) > this->debounceDelay)
84 if (reading < this->lastButtonState - this->readingTolerancy || reading > this->lastButtonState + this->readingTolerancy)
88 this->lastButtonState = reading;
90 for (
int i = 0; i < this->size; i++)
91 if (this->pButtons[i].IsPushed(reading))
93 foundID = this->pButtons[i].
GetId();
95 #ifdef COMMANDERS_DEBUG_MODE 96 Serial.print(F(
"Analog push button "));
98 Serial.println(F(
" pressed"));
102 this->lastDebounceTime = 0;
110 this->lastButtonPressed = -1;
113 #ifdef COMMANDERS_PRINT_COMMANDERS 114 void ButtonsCommanderAnalogPushes::printCommander()
116 Serial.print(F(
" AnalogPushes - Pin :"));
117 Serial.println(this->analogPin);
118 Serial.print(F(
" / Reading Accuracy: "));
119 Serial.println(this->readingTolerancy);
121 for (
int i = 0; i < this->size; i++)
123 Serial.print(F(
" "));
124 this->
GetItem(i)->printCommander();
static unsigned long RaiseEvent(unsigned long inId, COMMANDERS_EVENT_TYPE inEvent = COMMANDERS_EVENT_MOVEPOSITIONID, int inData = 0)