Monday, March 9, 2015

Arduino Blocks 4 - matrix keypad

This is just a quick lesson that expands a bit on the "button" lesson earlier. I just got a bunch of new toys and wanted to do something with one of them this evening for you.

If you want to buy one of these, here's the one I picked up, or you can just go to eBay and switch for 4x3 matrix array keypad.  These are a DOLLAR, or less in quantity.

FWIW there's also a 4x4 matrix that's only a little more and adds ABCD to the right, if you need a few more keys.

This is a matrix keyboard, so called because the keys are laid out in an X/Y grid and they're read by "scanning" across rows and columns, looking for a short between the X and Y lines (rows and columns).

As usual, the video is the best guide here.

Here's what the grid looks like:

Here's how I wired it up:

And here's the code

The code works by setting the pins attached to the three columns to input with pullup resistors, so that when nothing is pressed, those pins read HIGH (1).  Then one by one, the rows are switched to output and the value is set to LOW (0).  Then the columns are checked.  If any of the columns now read LOW then the button that is at the intersection of that row and column must be pressed, and we have a value.  If not then scanning continues.

No comments: