I’ve just finished making a groovy little library for button matrix keypads.

GitHub Page

Matrix keypads are fairly simple to use. They’ve got rows and columns, and each button connects a particular row to a given column.


To check if a switch is pressed – let’s say SW1 – you could put a digital high on Col1 and make Col2 – Col4 low. If Row1 is high then SW1 is pressed, otherwise SW1 is not pressed.

Reading the entire matrix is a matter of iteratively putting a high on each individual column and checking the state of each row.

Of course, this will only tell you the state of the keypad – if buttons are up or down. Generally speaking, you’ll need your program to perform some action when a button is pressed. The state of the keypad isn’t important; what is important is that something occurs when a button changes state. This paradigm is known as event-driven programming. The keypad library tracks the state of the keypad matrix and generates events when buttons are pressed or released.

Check out the example



Leave a Reply

Your email address will not be published. Required fields are marked *