mirror of
https://github.com/KevinMidboe/python-gpiozero.git
synced 2025-10-29 17:50:37 +00:00
Makes it much easier to test things - no copying'n'pasting just run the examples straight from the dir (after wiring stuff up)
35 lines
810 B
Python
35 lines
810 B
Python
import curses
|
|
from gpiozero import Robot
|
|
|
|
robot = Robot(left=(4, 14), right=(17, 18))
|
|
|
|
actions = {
|
|
curses.KEY_UP: robot.forward,
|
|
curses.KEY_DOWN: robot.backward,
|
|
curses.KEY_LEFT: robot.left,
|
|
curses.KEY_RIGHT: robot.right,
|
|
}
|
|
|
|
def main(window):
|
|
next_key = None
|
|
while True:
|
|
curses.halfdelay(1)
|
|
if next_key is None:
|
|
key = window.getch()
|
|
else:
|
|
key = next_key
|
|
next_key = None
|
|
if key != -1:
|
|
# KEY DOWN
|
|
curses.halfdelay(3)
|
|
action = actions.get(key)
|
|
if action is not None:
|
|
action()
|
|
next_key = key
|
|
while next_key == key:
|
|
next_key = window.getch()
|
|
# KEY UP
|
|
robot.stop()
|
|
|
|
curses.wrapper(main)
|