Question about Encoder library

I'm using Encoder library and am trying to find a way to preset the position. I would say I'm an intermediate level coder FWIW. I've looked at the library and because of the way the position variable is wrapped in a struct and the update function is designed to be called from an interrupt, I'm having a hard time figuring out a way to preset the position variable at startup. I know more advanced coders on forums aren't real keen on doing the work for others. I just need nudge in the right direction. Since Paul S. wrote the library, perhaps he can point me in the right direction. Thanks in advance for any help.

What I'm trying to do is use a 2 x 16 character LCD with a single encoder w/button to cycle through menu items and values. Double click to enter/exit the menu. Single click to enter/save & exit menu items or values. Rotate to scroll up/down the menu items or increase/decrease values. At startup I will have the values previously stored in the EEPROM loaded back into the variables.
 
Last edited:
The thing is, there will be several values saved to EEPROM and reloaded at startup. So if I then go into the menu I would like to have those settings be the starting values for the menu. Also when switching between and changing different values the position value of the encoder will still be from the last menu item value, not the new menu item.
 
I know I could have another variable to get the value of the encoder before it is rotated and use that as an offset. But some of the values can be negative and some cant witch would add another layer to it. It just seems much easier if I could just preset the position value in the library. But the way the library is written is a little above my skills.

I don't see a write() function in the library. Just update().
 
Reading through the library it seems the variable that holds the position is in a struct in the library. The update() function has that struct as an argument. But the documentation says "Do not call update() from outside an interrupt".
So how can I access that variable within the struct that holds it from outside an interrupt?
 
Back
Top