No, dir should be defined near the top of the source file, outside of any function as:
volatile int dir;
It needs to be a volatile because it is used in the ISR that figures out which way the encoder is turning. That storage specifier ensures that a fresh copy of dir is loaded any time it is referenced. If you don't do that, an optimizing compiler like the Arduino's GNU C++ compiler, may cache the variable and it becomes out of sync when used.
From: Eric Torraca <eric.torraca@...> To:[email protected] Sent: Friday, March 31, 2017 8:48 PM Subject: Re: [BITX20] Tuning with Si5351 and Rotary encoders
Thanks for the code Jack.?
Sorry it took so long for an update. The week kind of got away from me.
I'm still having some issues with it, but I think I'm making progress. A friend of mine who knows these things helped me sort out some compiling errors (we added short dir=0 in the beginning since it was telling me that dir?wasn't defined to scope in the loop).?
Now with some of the changes the display doesn't respond when the dial is turned. I think I know where that is in the code so I'll take a look and see if I can get it working.