Skip to content

Instantly share code, notes, and snippets.

@grandcat
Last active October 27, 2016 06:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grandcat/770b4b2591f5c15ea9b3cfce9c38e04b to your computer and use it in GitHub Desktop.
Save grandcat/770b4b2591f5c15ea9b3cfce9c38e04b to your computer and use it in GitHub Desktop.
Scans a button matrix of an old Internet radio. Only for debugging.
import wiringpi
pin_base = 65
i2c_addr = 0x20
#pins = [65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80]
ROWS = range(68, 68 + 4)
def initialize():
# Set all out pins to 0 (prevent floating)
for pin in ROWS:
wiringpi.pinMode(pin,1)
wiringpi.digitalWrite(pin,0)
# Set pins for input
for pin in range(65, 65 + 3):
wiringpi.pinMode(pin, 0)
def scan(row):
# Out high on current row
wiringpi.digitalWrite(row, 1)
# Scan columns
for col in range(65, 68):
in_val = wiringpi.digitalRead(col)
if in_val:
print("[{},{}] pressed".format(row, col))
wiringpi.digitalWrite(row, 0)
wiringpi.wiringPiSetup()
wiringpi.mcp23017Setup(pin_base,i2c_addr)
# Set all out pins to 0 (prevent floating)
for pin in range(65,81):
wiringpi.pinMode(pin,1)
wiringpi.digitalWrite(pin,0)
initialize()
for i in range(100):
for r in ROWS:
scan(r)
wiringpi.delay(200)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment