Trying to make simple countdown timer with encoder.
When setting time with encoder, when minutes hit 59, hours are ment to be incresed by 1, but hours are getting incremented
uncontrollably. :o
#define ENCODER_DO_NOT_USE_INTERRUPTS
#include <Encoder.h>
Encoder myEnc(D5, D2);
int brojanje = 0;
int hours = 0;
void setup() {
Serial.begin(9600);
Serial.println("Basic NoInterrupts Test:");
}
long position = -999;
void loop() {
long newPos = myEnc.read();
if (newPos != position) {
position = newPos / 4;
brojanje = position;
}
if (brojanje < 0) {
brojanje = 0;
}
if (brojanje >= 59){
brojanje = 0;
position = 0;
newPos = 0;
hours = hours + 1;
delay(10);
}
Serial.println((String) +hours+":"+brojanje);
}
Some counting variable in rottary enc is messed up.
Example, when i turn it CCW by 5 - 6 turns, in serial monitor is 0:0. But when i start to turn it CW i need to turn it again 6 turns to get counting from zero.
Cant figure it out.
myEnc.read();
Returns the accumulated position. This number can be positive or negative. myEnc.write(newPosition);
Set the accumulated position to a new number.
If i hit above 59, i must use myEnc.write = 0; to reset position of encoder. (Basic usage of encoder.h libary)