class TwoLineLCD(object): def __init__(self, lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows, lcd_backlight): self.lcd = LCD(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows, lcd_backlight, gpio=aGPIO.get_platform_gpio()) self.lcd.clear() self._columns = lcd_columns self._in_progress = None def clear(self): self.lcd.clear() def cancel(self): if self._in_progress and self._in_progress.active(): self._in_progress.cancel() self.clear() def message(self, line_1, line_2): self.cancel() if len(line_1) > self._columns: line_1 += " " # Padding when scrolling if len(line_2) > self._columns: line_2 += " " # Padding when scrolling self._in_progress = async .DelayedCall(0, self._message, line_1, line_2) def _message(self, line_1, line_2): self.lcd.home() self.lcd.message(line_1[:self._columns] + "\n" + line_2[:self._columns]) if len(line_1) > self._columns: line_1 = rotate(line_1) if len(line_2) > self._columns: line_2 = rotate(line_2) self._in_progress = async .DelayedCall(0.5, self._message, line_1, line_2)
#!/usr/bin/python from Adafruit_CharLCD import Adafruit_CharLCD from subprocess import * from time import sleep, strftime from datetime import datetime from w1thermsensor import W1ThermSensor lcd = Adafruit_CharLCD() lcd.begin(16, 1) sensor = W1ThermSensor() #temp_k = sensor.get_temperature(W1ThermSensor.KELVIN) #temp_f = sensor.get_temperature(W1ThermSensor.DEGREES_F) #temp_c = sensor.get_temperature(W1ThermSensor.DEGREES_C) lcd.clear() while 1: temp_all = sensor.get_temperatures([W1ThermSensor.DEGREES_C, W1ThermSensor.DEGREES_F]) lcd.message(datetime.now().strftime('%b %d %l:%M %p\n')) lcd.message(' %.1fF %.1fC' % (round(temp_all[1], 1),round(temp_all[0],1))) lcd.home() sleep(0)
time.sleep(0.02) return out # def clear_out(): global out out = '' return out # time.sleep(1) ipaddr = run_cmd(cmd) lcd.home() lcd.message('IP: %s' % (ipaddr)) time.sleep(3) lcd.clear() lcd.home() #ser.write(START_CAL) if (ser.isOpen() == False): ser.open() ser.write(SET_INCLINAISON) while t != 0: lcd.home() lcd.message('+14 incl. %s' % (t)) lcd.message(' Sec.\n') lcd.message(datetime.now().strftime(' %H:%M:%S \n')) t = t - 1