Everything you need to know is on the page you linked.
I also found this example. which claims to have reliable code.
and this one
I did not find any clear statement regarding the number of encoder counts per revolution (the resolution) so I don’t know if it is 360 (1 count /per degree of revolution) or what.
Perhaps this is obvious to someone who has worked with rotary encoders but I have not personally used one. If you find that out it would be useful to know. I found a comment on the Backshed page that states:
because of Bourns encoder has 128pulses/revolution
and
yes, the encoder label says:
ENA1P-B28
LDO128
1050M MEX
but nothing such can be found in catalog. Looks like an obsolete part and that’s why the price was so low. The encoder has resolution 128 pulses/turn. Closest type in catalog is ENA1P-B50. Works perfectly.
The module is designed so that a low is output when the switches are closed and a high when the switches are open.
The low is generated by placing a ground at Pin C and passing it to the CLK and DT pins when switches are closed.
The high is generated with a 5V supply input and pullup resistors, such that CLK and DT are both high when switches are open.
Not previously mentioned is the existence of of push button switch that is integral to the encoder. If you push on the shaft, a normally open switch will close. The feature is useful if you want to change switch function. For example, you may wish to have the ability to between coarse and fine adjustments.
Does yours have the switch that closes when you push on the shaft ?
before using encoder i wanna know how to change lcd page every 10 seconds, can you help me with the sketch?
Use the millis() function.
Look at the Blinkwithoutdelay IDE example (File\Examples\Digital\BlinkWithoutDelay)
Look at the ENTIRE sketch, from start to finish.
Note value of constant/variable interval
const long interval = 1000; // interval at which to blink (milliseconds)
In this sketch, interval is a constant because the purpose of the sketch is to blink the led every second. Obviously, if you wanted an interval that could be changed under program control you would make a variable instead of a constant, to allow changing the interval “on the fly” . If you are fine with a 10 second interval then just change it to 10000. That’s fairly straight forward.
All the code you need to use the encoder is on the page you linked.
As far as scrolling through LCD pages, I would advise rewriting ALL the LCD code into something more structured and organized. It should not take you very long to figure out how to write a function called
“page_1()” that sets up the LCD with some specific information. It should be just as easy to write nine more functions named page_2() , page_3(), etc . etc.
Each function displays the information reserved for that page
ie:
void page_1()
{
lcd.setCursor(0,0);
lcd.print("[something for page 1, line 1"); //display page 1, line 1
lcd.print(units); // print units for page 1, line 1
lcd.setCursor(0,1);
lcd.print("something for page 1, line 2"); //display page 1, line 2
lcd.print([units for page 1 , line 2]); //print units for page 1, line 2
}
void page_2()
{
lcd.setCursor(0,0);
lcd.print("[something for page 2, line 1"); //display page 1, line 1
lcd.print(units); // print units for page 1, line 1
lcd.setCursor(0,1);
lcd.print("something for page 2, line 2"); //display page 1, line 2
lcd.print([units for page 1 , line 2]); //print units for page 1, line 2
}
// etc. etc. etc.
if you use an IF statement for
int encoderPosCount = 0;
128/10=12.8
such that IF encoderPosCount >= 0 && < 12
var = 1
such that IF encoderPosCount >= 13 && < 24
var = 2
such that IF encoderPosCount >= 24 && < 36
var = 3
etc , etc etc.
This divides the 128 steps of a revolution into 10 steps that can be used assign the value of “var”
for the CASE statement.
Having done that, you should be able to use the CASE() function where “var” = the encoder value such that the value returned by the encoder service routine is used to select the CASE
and each case corresponds to a different LCD page.
ue:
CASE 1 = PAGE 1
CASE 2 = PAGE 2
etc., etc. etc.
Software is really not my area of expertise but that’s what I would do.
I could probably write the code if I had to but I think that’s your job.