Hello,
I wish to make a menu system so i can control and change settings of different sensors
My first step is to make a working menu using the rottary encoder.
First approach was with if statement and counter on Rottary,
Problem lcd would flicker and printing only the first line
Then tried using cases failed to make it work
Then thought to use void loops i also failed.
Please what is the best approach for it on a arduino nano?
What have you tried? POST THE SKETCH.
Not posting your code is like asking a car mechanic to diagnose and fix your car over the phone. Not gonna' happen.
If you post your code as described in the how to use this forum sticky, more members will read it.
Post your sketch (code), schematic in CAD or a picture of a hand drawn circuit in jpg or png. PLEASE- not a pretty Fritzing picture.
Using 'if' statement should be OK for this purpose. There is a high possibility of missing edges/clicks of the encoder if it is moved quickly, but when selecting from a menu, this is not normally a problem, because the user gets continuous visual confirmation of the currently selected menu item. They may not notice some missing edges/clicks.
i found a ready code by ELECTRONOOBS that seems very close to what i need
i am now having problems making it work with an arduino NANO
i am having problem with these lines!!! (i think)
PCICR |= (1 << PCIE0); //enable PCMSK0 scan
PCMSK0 |= (1 << PCINT0); //Set pin (D8)trigger an interrupt on state change.
PCMSK0 |= (1 << PCINT1); //Set pin (D9) trigger an interrupt on state change.
DDRB &= B11111110; //8, 9 as input for the encoder clock and data pins
Last_State = (PINC & B00000001); //pin 8 state (clock pin)?
//Interruption vector
ISR(PCINT0_vect){
clk_State = (PINB & B00000001); //pin 8 state, clock pin?
dt_State = (PINB & B00000010);
if (clk_State != Last_State){
// If the data state is different to the clock state, that means the encoder is rotating clockwise
if (dt_State != clk_State) {
counter ++;
}
else {
counter --;
}
}
Last_State = clk_State; // Updates the previous state of the data with the current state
}
So... this code is unchanged from what you found on the "electro noobs" page? And you think it might not be compatible with your Nano? What type of Arduino was the code written for? If it was Uno, then no problem, Uno and Nano have the exact same chip. If it was written for Mega, Leonardo, Due, then perhaps you are correct.