I am implementing a key matrix in Circuitpython on a Raspberry Pi Pico.
I have gotten to the point where I can scan and read fine. Now I need to add debouncing. I would like to use adafruit_debouncer for that.
First I fell for the mistake of simply debouncing the column input-pins with hilarious results as the debouncer tried to make sense of the values while the rows where being scanned...
Now I want to create a debouncer for each key and I think I should be able to use adafruit_debouncer by not giving it a DigitalIO-instance to work on but a lambda that looks at a specific cell in my two-dimensional array of key states.
Given two suitably sized 2D-arrays of keystates and debouncers I create them like this:
for rowindex in range(len(rowpins)):
for colindex in range(len(colpins)):
debouncers[rowindex][colindex] = adafruit_debouncer.Debouncer(lambda: keystates[rowindex][colindex])
After doing each scan that updates keystates[][]
, putting in Trues and Falses according to wether a key is down or not, I then iterate over debouncers[][]
, call update()
on each and then query their value
.
Unfortunately no debouncer seems to be able to see the True
values from the array. At least none ever report a True
themselves.
What is my mistake?