adafruit / Adafruit-Raspberry-Pi-Python-Code

Adafruit library code for Raspberry Pi
1.43k stars 686 forks source link

Added getKeys() method to read key presses recorded by HT16K33 keyscan #122

Closed gooligumelec closed 9 years ago

gooligumelec commented 9 years ago

Although the HT16K33 (the "LEDBackpack") is commonly used to drive LEDs, it is also able to scan keys arranged in a 13 x 3 matrix. I needed to be able to read some jumpers (just like keys, but always on or off) to a HT16K33-based display project I'm working on, so I added a "getKeys()" method to Adafruit_LEDBackpack, which returns the current key scan result for a given row of 13 keys, as a 13-bit value where a '1' indicated a (debounced) key press since the last read. Note that if a key remains pressed, it will continue to be seen (return a '1') in subsequent scans. For example, if keys 3 and 5 in row 0 have been pressed, getKeys(0) will return 0b0000000010100.