class LCD(): # All avalaible colors COLOR_RED = 0 COLOR_YELLOW = 1 COLOR_GREEN = 2 COLOR_TEAL = 3 COLOR_BLUE = 4 COLOR_VIOLET = 5 COLOR_ON = 6 COLOR_OFF = 7 def __init__(self): self.__lcd = Adafruit_CharLCDPlate() self.__buttons = ( self.__lcd.LEFT, self.__lcd.UP, self.__lcd.DOWN, self.__lcd.RIGHT, self.__lcd.SELECT, ) self.__col = ( self.__lcd.RED, self.__lcd.YELLOW, self.__lcd.GREEN, self.__lcd.TEAL, self.__lcd.BLUE, self.__lcd.VIOLET, self.__lcd.ON, self.__lcd.OFF ) def stop(self): self.change_color(7) self.__lcd.clear() def clear(self, clear_background): if clear_background: self.change_color(6) self.__lcd.clear() def change_color(self, index): self.__lcd.backlight(self.__col[index]) def set_message(self, msg): self.__lcd.message(msg) def button_pressed(self, index): return self.__lcd.buttonPressed(self.__buttons[index])
(times + ' ')[0:16]) else: lcd.message(scroller.scroll()[0:16] + '\n' + \ (times + ' ')[0:16]) else: lcd.message((playStatus + ' ')[0:16] + '\n' + \ (times + ' ')[0:16]) # Poll the buttons most of the sleep time, to make them responsive the plan is to # poll the buttons for 400ms and then update the status on the display # If we sleep for 40ms between each poll time and have five buttons that equals to 200 ms # Two iterations of this gives us 400 ms. # for i in range (0, 10): for i in range (0, 5): for b in btn: if lcd.buttonPressed(b): if isinstance(tmr, threading._Timer): lcd.backlight(lcd.ON) tmr.cancel() tmr = None if b is lcd.RIGHT: subprocess.Popen('mpc next', shell=True) sleep(0.2) # Sleep a little extra to avoid dubble registrations if b is lcd.LEFT: subprocess.Popen('mpc prev', shell=True) sleep(0.2) # Sleep a little extra to avoid dubble registrations if b is lcd.UP: # subprocess.Popen('mpc play', shell=True) subprocess.Popen('mpc volume +1', shell=True) # sleep(0.2) # Sleep a little extra to avoid dubble registrations
(times + ' ')[0:16]) else: lcd.message(scroller.scroll()[0:16] + '\n' + \ (times + ' ')[0:16]) else: lcd.message((playStatus + ' ')[0:16] + '\n' + \ (times + ' ')[0:16]) # Poll the buttons most of the sleep time, to make them responsive the plan is to # poll the buttons for 400ms and then update the status on the display # If we sleep for 40ms between each poll time and have five buttons that equals to 200 ms # Two iterations of this gives us 400 ms. # for i in range (0, 10): for i in range(0, 5): for b in btn: if lcd.buttonPressed(b): if isinstance(tmr, threading._Timer): lcd.backlight(lcd.ON) tmr.cancel() tmr = None if b is lcd.RIGHT: subprocess.Popen('mpc next', shell=True) sleep( 0.2 ) # Sleep a little extra to avoid dubble registrations if b is lcd.LEFT: subprocess.Popen('mpc prev', shell=True) sleep( 0.2 ) # Sleep a little extra to avoid dubble registrations