import curses
import RPi.GPIO as GPIO
import os
GPIO.setmode(GPIO.BOARD)
GPIO.setup(7,GPIO.OUT)
GPIO.setup(11,GPIO.OUT)
GPIO.setup(12,GPIO.OUT)
GPIO.setup(13,GPIO.OUT)
screen = curses.initscr()
curses.noecho()
curses.cbreak()
screen.keypad(True)
try:
while True:
char = screen.getch()
if char == ord('q'):
break
elif char == curses.KEY_UP:
GPIO.output(7,False)
GPIO.output(11,True)
GPIO.output(12,False)
GPIO.output(13,True)
elif char == curses.KEY_DOWN:
GPIO.output(7,True)
GPIO.output(11,False)
GPIO.output(12,True)
GPIO.output(13,False)
elif char == curses.KEY_RIGHT:
GPIO.output(7,True)
GPIO.output(11,False)
GPIO.output(12,False)
GPIO.output(13,True)
elif char == curses.KEY_LEFT:
GPIO.output(7,False)
GPIO.output(11,True)
GPIO.output(12,True)
GPIO.output(13,False)
elif char == 10:
GPIO.output(7,False)
GPIO.output(11,False)
GPIO.output(12,False)
GPIO.output(13,False)
if char == ord('m'):
os.system('omxplayer -o local song1.mp3')
if char == ord('j'):
os.system('omxplayer -o local song2.mp3')
finally:
curses.nocbreak(); screen.keypad(0); curses.echo()
curses.endwin()
GPIO.cleanup()
Comments