mirror of
https://github.com/KevinMidboe/oled_workout_tracker.git
synced 2025-10-29 17:50:28 +00:00
checking encoder built in button for change in value and removed readFromPotValue function.
This commit is contained in:
@@ -126,40 +126,27 @@ void drawPushups(int count) {
|
|||||||
display.display();
|
display.display();
|
||||||
}
|
}
|
||||||
|
|
||||||
int positionBuffer = 10;
|
|
||||||
int getPotValue() {
|
|
||||||
return analogRead(potPin) / positionBuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
void checkButtonState() {
|
||||||
|
int btnState = digitalRead(SW);
|
||||||
|
|
||||||
bool mode = false;
|
//If we detect LOW signal, button is pressed
|
||||||
|
if (btnState == LOW) {
|
||||||
|
//if 50ms have passed since last LOW pulse, it means that the
|
||||||
|
//button has been pressed, released and pressed again
|
||||||
|
if (millis() - lastButtonPress > 50) {
|
||||||
|
Serial.println("Button pressed!");
|
||||||
|
mode = !mode;
|
||||||
|
|
||||||
int pos = 0;
|
if (mode == false) {
|
||||||
int currentPos;
|
drawPushups(counter);
|
||||||
bool active;
|
} else {
|
||||||
|
displayMenu();
|
||||||
unsigned long lastEvent = 0;
|
}
|
||||||
unsigned long currentTime;
|
|
||||||
const long timeout = 1000;
|
|
||||||
void displayNumberWithPotValue() {
|
|
||||||
currentPos = getPotValue();
|
|
||||||
if (currentPos < pos - 2 || currentPos > pos + 2) {
|
|
||||||
active = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (active && mode == false) {
|
|
||||||
currentTime = millis();
|
|
||||||
if (currentTime - lastEvent > timeout) {
|
|
||||||
active = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
currentPos = getPotValue();
|
// Remember last button press event
|
||||||
if (currentPos != pos) {
|
lastButtonPress = millis();
|
||||||
lastEvent = currentTime;
|
|
||||||
pos = currentPos;
|
|
||||||
drawPushups(pos);
|
|
||||||
}
|
|
||||||
delay(10);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user