Skip to content

Instantly share code, notes, and snippets.

@craigjb
Created July 16, 2023 20:45
Show Gist options
  • Save craigjb/28f0b80f8f1f842e1c011b3dc90f47dc to your computer and use it in GitHub Desktop.
Save craigjb/28f0b80f8f1f842e1c011b3dc90f47dc to your computer and use it in GitHub Desktop.
Key matrix test with GreatFET
import time, curses
from curses import wrapper
from greatfet import GreatFET
def main():
gf = GreatFET()
columns = [
gf.gpio.get_pin("J1_P3"),
gf.gpio.get_pin("J1_P4"),
gf.gpio.get_pin("J1_P5"),
gf.gpio.get_pin("J1_P6"),
]
for col in columns:
col.set_direction(gf.gpio.DIRECTION_IN)
rows = [
gf.gpio.get_pin("J1_P10"),
gf.gpio.get_pin("J1_P9"),
gf.gpio.get_pin("J1_P8"),
gf.gpio.get_pin("J1_P7"),
]
for row in rows:
row.set_direction(gf.gpio.DIRECTION_OUT)
row.write(True)
stdscr = curses.initscr()
curses.noecho()
curses.cbreak()
curses.start_color()
curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_GREEN)
try:
while True:
for (row_id, row) in enumerate(rows):
row.write(False)
time.sleep(0.001)
for (col_id, col) in enumerate(columns):
if not col.read():
stdscr.addstr(
row_id,
(col_id * 3) + 1,
"O",
curses.color_pair(1)
)
else:
stdscr.addstr(
row_id,
(col_id * 3) + 1,
"-"
)
row.write(True)
time.sleep(0.001)
stdscr.refresh()
time.sleep(1.0 / 60.0)
except KeyboardInterrupt:
pass
curses.nocbreak()
curses.echo()
curses.endwin()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment