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 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] > 1023)
36 Serial.print(F(
"Analog push buttons. Invalid value "));
37 Serial.print(inpButtonValues[i]);
38 Serial.print(F(
" for button "));
40 Serial.println(F(
". Value must between 0 and 1023 !"));
43 this->pButtons[i].
begin(inpIds[i], inpButtonValues[i], inTolerancy);
46 pinMode(this->analogPin, INPUT);
51 for (
int i = 0; i < this->size; i++)
52 if (this->pButtons[i].
GetId() == inId)
53 return &(this->pButtons[i]);
62 if (this->analogPin == 0)
66 int reading = analogRead(this->analogPin);
73 if (this->lastDebounceTime == 0 && (reading < this->lastButtonState - this->readingTolerancy || reading > this->lastButtonState + this->readingTolerancy))
76 this->lastDebounceTime = millis();
79 if (this->lastDebounceTime > 0 && (millis() - this->lastDebounceTime) > this->debounceDelay)
85 if (reading < this->lastButtonState - this->readingTolerancy || reading > this->lastButtonState + this->readingTolerancy)
89 this->lastButtonState = reading;
91 for (
int i = 0; i < this->size; i++)
92 if (this->pButtons[i].IsPushed(reading))
94 foundID = this->pButtons[i].
GetId();
96 #ifdef COMMANDERS_DEBUG_MODE 97 Serial.print(F(
"Analog push button "));
99 Serial.println(F(
" pressed"));
103 this->lastDebounceTime = 0;
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);
121 Serial.print(F(
" / Debounce delay: "));
122 Serial.print(this->debounceDelay);
124 for (
int i = 0; i < this->size; i++)
126 Serial.print(F(
" "));
127 this->
GetItem(i)->printCommander();
static unsigned long RaiseEvent(unsigned long inId, COMMANDERS_EVENT_TYPE inEvent = COMMANDERS_EVENT_MOVEPOSITIONID, int inData = 0)