Better way to drive button matrix?
Rayman
Posts: 14,640
in Propeller 2
I'm making a button matrix board that will hook up something like this image from https://www.embeddedrelated.com/showarticle/519.php
This article describes what I guess is the usual way for doing this...
Drive one of the rows and then scan the columns.
Am thinking about if there's any magic on the P2 smartpins that could automate this...
Haven't come up with anything yet...
Comments
Chip made that "5 buttons on one pin" example where it uses the ADC to read multiple buttons from just one pin (included with PNut). You could do that on multiple pins at once, which would be actually be more efficient than a matrix for low pin counts...
etc.
Array I'm looking at is 5x6. But, saving pins doesn't help in my case.
Would like to find a way to not use a cog to save battery life though.
Looking at making a calculator...
Actually, maybe the regular way is just fine.
Guess can't do math and check buttons at same time, but maybe math is so fast it doesn't matter...
Here's photo of current mock up to give an idea of what this is about...
Want to power by LiPo...
Wiring up the buttons now in Eagle.
Guess good thing is can at least use internal pullups/pulldowns so don't need any resistors.
Since when would you need a cog, anyways? A passive matrix like that can respond pretty fast (esp. if instead of relying on pullup/down, you drive the columns to their unpressed state in-between rows), so reading it shouldn't take much time at all.
To Ada's point about speed -- and this is in Propeller Tool (PNut) using safe, simplistic code.
Edit: Made row drive through 1.5K
Edit: Added Evan's filter suggestion
None of the smartpin modes will help. But you'll want to use the debounce hardware in front of each smartpin. I'd use the maximum of 8 samples spread over maybe a few milliseconds. The default for "filt3" I feel is too sluggish.
Of course, once the debounce is in use, then you'll want to setup a regular sampling interval where you read the inputs just before changing the outputs. Pretty small overhead but has to be the Cog doing this really.
Thinking more about smartpins for this... Maybe rows can be set up in a slow NCO mode with each giving a staggered pulse so that only one is on at a time. Then, use an interrupt to go off whenever a high is detected on a col pin. Hopefully, with some smartpin filtering on the col inputs...