forked from Akcelerometry_drgania_WMT/PI_mikrokontroler
Naprawa isPressed() - dodanie wykrywania zbocza opadajacego, co rozwiazuje problem wielokrotnego wyzwalania akcji przy przytrzymaniu
This commit is contained in:
@@ -47,6 +47,10 @@ private:
|
|||||||
void constrainValue(int &value, int minVal, int maxVal);
|
void constrainValue(int &value, int minVal, int maxVal);
|
||||||
void printField(const char *label, int value);
|
void printField(const char *label, int value);
|
||||||
|
|
||||||
|
bool lastState1_ = true;
|
||||||
|
bool lastState2_ = true;
|
||||||
|
bool lastState3_ = true;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -13,15 +13,28 @@ void Settings::begin() {
|
|||||||
pinMode(BTN_DOWN, INPUT_PULLUP);
|
pinMode(BTN_DOWN, INPUT_PULLUP);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Zwraca true, jeśli przycisk jest wciśnięty
|
// Zwraca true, jeśli przycisk został WŁAŚNIE wciśnięty (zbocze opadające)
|
||||||
bool Settings::isPressed(uint8_t btnIndex) {
|
bool Settings::isPressed(uint8_t btnIndex) {
|
||||||
//ESP_LOGI(TAG_SETTINGS, "BTN check");
|
bool currentState, isNewlyPressed = false;
|
||||||
switch (btnIndex) {
|
switch (btnIndex) {
|
||||||
case 1: return digitalRead(BTN_UP) == LOW;
|
case 1:
|
||||||
case 2: return digitalRead(BTN_OK) == LOW;
|
currentState = digitalRead(BTN_UP);
|
||||||
case 3: return digitalRead(BTN_DOWN) == LOW;
|
isNewlyPressed = (currentState == LOW && lastState1_ == HIGH);
|
||||||
|
lastState1_ = currentState;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
currentState = digitalRead(BTN_OK);
|
||||||
|
isNewlyPressed = (currentState == LOW && lastState2_ == HIGH);
|
||||||
|
lastState2_ = currentState;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
currentState = digitalRead(BTN_DOWN);
|
||||||
|
isNewlyPressed = (currentState == LOW && lastState3_ == HIGH);
|
||||||
|
lastState3_ = currentState;
|
||||||
|
break;
|
||||||
default: return false;
|
default: return false;
|
||||||
}
|
}
|
||||||
|
return isNewlyPressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kombinacja 1 i 3 jednocześnie
|
// Kombinacja 1 i 3 jednocześnie
|
||||||
|
|||||||
Reference in New Issue
Block a user