Advertisement
akellyirl

radio.py

Aug 12th, 2015
806
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. import os
  2. from nanpy import Arduino, Lcd
  3.  
  4. Arduino.pinMode(14, input)
  5.  
  6. lcd = Lcd([8,9,4,5,6,7],[16,2])
  7.  
  8. max_trax = 6
  9.  
  10. def getKey():
  11.    val = Arduino.analogRead(14)
  12.    if val == 1023:
  13.       return "NONE"
  14.    elif val < 100:
  15.       return "RIGHT"
  16.    elif val < 150:
  17.       return "UP"
  18.    elif val < 330:
  19.       return "DOWN"
  20.    elif val < 510:
  21.       return "LEFT"
  22.    elif val < 750:
  23.       return "SEL"
  24.    else:
  25.       return "KBD_FAULT"
  26.  
  27.  
  28. def getTrack():
  29.    L= [S.strip('\n') for S in os.popen('mpc').readlines()]
  30.    station = L[0][0:15]
  31.    track = L[0][-16:-1]
  32.    lcd.printString(16*" ", 0, 0)
  33.    lcd.printString(station, 0, 0)
  34.    lcd.printString(16*" ", 0, 1)
  35.    lcd.printString(track, 0, 1)
  36.    print L
  37.    print station
  38.    print track
  39.  
  40. track_num = 1
  41. os.system("mpc play "+str(track_num))
  42. getTrack()
  43.  
  44. while True:
  45.    key = getKey()
  46.    if key == "RIGHT":
  47.       track_num += 1
  48.       if track_num > max_trax:
  49.          track_num = max_trax
  50.       os.system("mpc play " + str(track_num))
  51.       getTrack()
  52.    elif key == "LEFT":
  53.       track_num -= 1
  54.       if track_num < 1:
  55.          track_num = 1
  56.       os.system("mpc play " + str(track_num))
  57.       getTrack()
  58.    elif key == "SEL":
  59.       os.system("mpc toggle")
  60.       getTrack()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement