mirror of
https://github.com/KevinMidboe/oled_workout_tracker.git
synced 2025-12-28 21:01:07 +00:00
Function for reading encoder and updating counter.
This commit is contained in:
@@ -79,6 +79,34 @@ void displayFromSerialInput() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
boolean readEncoderAndUpdateCounter() {
|
||||||
|
currentStateCLK = digitalRead(CLK);
|
||||||
|
|
||||||
|
// If last and current state of CLK are different, then pulse occurred
|
||||||
|
// React to only 1 state change to avoid double count
|
||||||
|
if (currentStateCLK != lastStateCLK && currentStateCLK == 1){
|
||||||
|
|
||||||
|
// If the DT state is different than the CLK state then
|
||||||
|
// the encoder is rotating CCW so decrement
|
||||||
|
if (digitalRead(DT) != currentStateCLK) {
|
||||||
|
counter --;
|
||||||
|
currentDir ="CCW";
|
||||||
|
} else {
|
||||||
|
// Encoder is rotating CW so increment
|
||||||
|
counter ++;
|
||||||
|
currentDir ="CW";
|
||||||
|
}
|
||||||
|
|
||||||
|
lastStateCLK = currentStateCLK;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
lastStateCLK = currentStateCLK;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void drawHeader(String textToDisplay) {
|
void drawHeader(String textToDisplay) {
|
||||||
display.setTextSize(1);
|
display.setTextSize(1);
|
||||||
display.setCursor(2,0);
|
display.setCursor(2,0);
|
||||||
|
|||||||
Reference in New Issue
Block a user