micropython-rotary
micropython-rotary copied to clipboard
Listeners lost when instantiating multiple RotaryIRQs
Hi,
I'm having issues with the following sample code:
aaa = RotaryIRQ(
pin_num_clk=26,
pin_num_dt=27,
min_val=0,
max_val=10,
reverse=True,
range_mode=RotaryIRQ.RANGE_WRAP)
aaa.add_listener(lambda: print('aaa'))
bbb = RotaryIRQ(
pin_num_clk=26,
pin_num_dt=27,
min_val=0,
reverse=True,
range_mode=RotaryIRQ.RANGE_UNBOUNDED)
bbb.add_listener(lambda: print('bbb'))
(Note: I'm using the same physical encoder with the same pins, but with otherwise different parameters. Also, I'm using a Raspberry Pi Pico with the latest version of Micropython.)
I would expect to see both aaa and bbb printed every time I move the rotary encoder. However, only bbb gets printed.
In other terms, it looks like instantiating a second RotaryIRQ causes the first one to lose its listeners.
Is that a bug or am I missing something?
Thanks,
Julien