예제 #1
0
파일: Lcd.py 프로젝트: amiceli/i2clcd
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])
예제 #2
0
파일: haTacoma.py 프로젝트: raelinamarie/ha
 def lcdDisplay():
     lcd = Adafruit_CharLCDPlate(busnum = 1, addr=0x24)
     lcd.backlight(lcd.TEAL)
     while True:
         altitude = resources.getRes("altitude").getState()
         heading = resources.getRes("heading").getState()
         direction = dirs[int((heading+11.25)%360/22.5)]
         outsideTemp = resources.getRes("outsideTemp").getState()
         coolantTemp = resources.getRes("coolantTemp").getState()*9/5+32
         battery = resources.getRes("battery").getState()
         message = "%5d' %03s %03d\n%3dF %3dF %4.1fV" % (altitude, direction, heading, outsideTemp, coolantTemp, battery)
         lcd.clear()
         lcd.message(message)
         time.sleep(10)
예제 #3
0
        songName = ''
        playStatus = '[stopped]'
        times = '0:00/0:00 (0%)'

    lcd.setCursor(0,0)

    artistSong = (songName)
    if artistSong != lastArtistSong:
        scroller.setNewText(artistSong)
        lastArtistSong = artistSong

    # Aubrey - If the songname is shorter than 16, just display it,
    # else, scroll it...
    if songName != '':
        if len(songName) < 16:
            lcd.message(artistSong + '                            \n' + \
            (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):
예제 #4
0
        songName = ''
        playStatus = '[stopped]'
        times = '0:00/0:00 (0%)'

    lcd.setCursor(0, 0)

    artistSong = (songName)
    if artistSong != lastArtistSong:
        scroller.setNewText(artistSong)
        lastArtistSong = artistSong

    # Aubrey - If the songname is shorter than 16, just display it,
    # else, scroll it...
    if songName != '':
        if len(songName) < 16:
            lcd.message(artistSong + '                            \n' + \
            (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):
예제 #5
0
class Device(object):
    def __init__(self):
        self.lcd = None
        self._color = RED
        self._lastbuttons = 0
        self._lock = threading.Lock()

    def get_buttons(self):
        pressed = []
        self._lock.acquire()
        try:
            if not self.lcd:
                return []
            buttons = self.lcd.buttons()
        finally:
            self._lock.release()
        for button in BUTTONS:
            power = 1 << button
            if (buttons & power) == 0:
                if (self._lastbuttons & power) != 0:
                    pressed.append(button)

        self._lastbuttons = buttons
        return pressed

    def color(self, color):
        if self.lcd:
            self._lock.acquire()
            self.lcd.backlight(color)
            self._lock.release()
        self._color = color

    def on(self):
        self._lock.acquire()
        self.lcd = Adafruit_CharLCDPlate()
        self.lcd.begin(WIDTH, 2)
        self.lcd.clear()
        self.lcd.backlight(self._color)
        self._lock.release()

    def off(self):
        if self.lcd:
            self._lock.acquire()
            self.lcd.clear()
            self.lcd.stop()
            self.lcd = None
            self._lock.release()

    def display(self, line1 = None, line2 = None):
        if not self.lcd:
            self.on()

        self._lock.acquire()
        if line1 is not None:
            line1 = str(line1).ljust(WIDTH)
            self.lcd.setCursor(0, 0)
            self.lcd.message(line1)
        if line2 is not None:
            line2 = str(line2).ljust(WIDTH)
            self.lcd.setCursor(0, 1)
            self.lcd.message(line2)
        self._lock.release()