I changed this piece of code and it works a bit better now. I figured if there is a 0 state for the buttons, there has to be a 0 state for the encoder too.
}else{
if (reading = (encoder0Pos = 0)) { // I added this and it works better now
lastButtonPushed=0;
}
}
I also changed this and now it is more stable. Encoder takes steps of 4 numbers up or down, but sometimes 3, so sometimes i turn one step and the menu stays the same, How can I fix this?
//Down button
// read the state of the switch into a local variable:
//reading = digitalRead(buttonPinRight);
reading = encoder0Pos + 1 / 4;
and
//Up button
// read the state of the switch into a local variable:
//reading = digitalRead(buttonPinLeft);
reading = encoder0Pos - 1 / 4;
There is another challenge, I can Scroll between Item1SubItem1 en Item1SubItem2, but further forward or backward doesnt work.