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 (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)
86 this->lastButtonState = reading;
88 for (
int i = 0; i < this->size; i++)
89 if (this->pButtons[i].IsPushed(reading))
91 foundID = this->pButtons[i].
GetId();
93 #ifdef COMMANDERS_DEBUG_MODE 94 Serial.print(F(
"Analog push button "));
96 Serial.println(F(
" pressed"));
100 this->lastDebounceTime = 0;
105 lastButtonState = reading;
111 this->lastButtonPressed = -1;
114 #ifdef COMMANDERS_PRINT_COMMANDERS 115 void ButtonsCommanderAnalogPushes::printCommander()
117 Serial.print(F(
" AnalogPushes - Pin :"));
118 Serial.println(this->analogPin);
119 Serial.print(F(
" / Reading Accuracy: "));
120 Serial.println(this->readingTolerancy);
122 for (
int i = 0; i < this->size; i++)
124 Serial.print(F(
" "));
125 this->
GetItem(i)->printCommander();
static unsigned long RaiseEvent(unsigned long inId, COMMANDERS_EVENT_TYPE inEvent = COMMANDERS_EVENT_MOVEPOSITIONID, int inData = 0)