Global Variable in Rotary Encoder Library
burck1 opened this issue · comments
Friday night I created and successfully tested 2 libraries, SimpleRotaryEncoder and RotaryEncoder. These libraries handle data logged from the rotary encoders on each wheel.
SimpleRotaryEncoder keeps track of a single sensor on a wheel (there are 2 total) and outputs the count of pulses recorded.
RotaryEncoder keeps track of both sensors. It outputs a count of the the number of pulses as well, but it will subtract from the count when the wheel is turned in reverse.
The issue I am having is the attachInterrupt function requires me to input a static function handle. So I had to create a wrapper method (_interruptHandler_wrapper) that uses a global variable to call the function. This means that if more than one RotaryEncoder/SimpleRotaryEncoder is created in the main program, only one works since they have the same global variables.
I need help getting rid of the global variables and and figuring out a different way to setup the interrupt handler.