예제 #1
0
class _PCF8574_LCD(_LCD):
    def __init__(self, address=None, cols=20, rows=2, backlight_enabled=True):
        from RPLCD.i2c import CharLCD
        self.device = CharLCD(i2c_expander='PCF8574',
                              address=address,
                              cols=cols,
                              rows=rows,
                              backlight_enabled=backlight_enabled)

        super(_PCF8574_LCD, self).__init__(cols=cols, rows=rows)

    def on(self):
        self.device.backlight_enabled = True

    def off(self):
        self.device.backlight_enabled = False

    def redraw(self, row=None):
        self.device.home()
        for r in range(self.rows):
            if row is None or row == r:
                value = self._get_value_at(r)
                self.device.write_string(value)
                self.device.crlf()
예제 #2
0
normal_temperature = 27

try:
    while True:
        time.sleep(3)
        lcd.clear()
        humidity, temperature = Adafruit_DHT.read_retry(dht_type, bcm_pin)
        humid = round(humidity, 1)  #여기선 연산비교를 해야되서 str()하면 안됨.
        temp = round(temperature, 1)
        print(temp, humid)  #초기 : 콘솔에 현재 온/습도 출력
        GPIO.setmode(GPIO.BCM)  #LED 설정
        GPIO.setup(16, GPIO.OUT)  #LED1 red

        if normal_temperature < temp:  #일정 온도(27도)보다 높을 때
            lcd.write_string('201835652')  #학번 띄우고
            lcd.crlf()
            lcd.write_string('Need Cooling')  # 출력
            GPIO.output(16, True)  # LED1 red on
        else:  #일정 온도 이하로 내려가면
            GPIO.cleanup()  #LED off
            lcd.write_string('Temp ')  #현재 온/습도 띄우기
            lcd.write_string(str(temp))  #대신 lcd에 띄울때 str()해야함.
            lcd.write_string('C ')
            lcd.crlf()
            lcd.write_string('Humid ')
            lcd.write_string(str(humid))
            lcd.write_string('% ')
except KeyboardInterrupt:  # 프로그램 종료 시 lcd차단, led화면 지움.
    GPIO.cleanup()
    lcd.clear()
    GPIO.setwarnings(False)
예제 #3
0
#dht를 이용해 습도,온도를 측정하고 lcd 화면에 표시하는 실습.
from RPLCD.i2c import CharLCD
import Adafruit_DHT
import time

dht_type = 11  # DHT 타입
bcm_pin = 23   # 핀 번호
lcd = CharLCD('PCF8574',0x27)

try:
    while True:
        time.sleep(3)
        lcd.clear()
        humidity, temperature = Adafruit_DHT.read_retry(dht_type, bcm_pin)  #read_retry(sensor, pin) : DHT 센서의 값을 읽어옴.
        humid = str(round(humidity,1))       #습도 소수점 1째자리에서 올림하고 문자화(str)
        temp = str(round(temperature,1))     #온도 소수점 1째자리에서 올림하고 문자화(str)
        print(temp,humid)             #콘솔에도 띄우기
        lcd.write_string('TEMP ')
        lcd.write_string(temp)      
        lcd.write_string('C ')        # ex) TEMP 36C
        lcd.crlf()                    # 한줄 띄움.
        lcd.write_string('HUMID ')
        lcd.write_string(humid)
        lcd.write_string('% ')        # ex) HUMID 80%
except KeyboardInterrupt:
    lcd.clear()                  #프로그램 종료 시 LCD 화면의 문자를 지우고 커서 위치 원상복귀.
예제 #4
0
class ScreenManager:
    """Manages Screens

    Creates the arborescence needed for a LedPanel and manages it

    Please call cleanup() once you have finished.
    """
    def __init__(self, panel):
        self.panel = panel

        self.lcd_lock = threading.RLock()
        self.gpio_lock = threading.Lock()

        home = StartScreen('HOME', 'LedPanel 289', self,
                           'Made by N.V.Zuijlen')
        main_menu = MenuScreen('MAIN_MENU', 'Menu', self)
        manual_menu = MenuScreen('MANUAL_MENU', 'Manuel', self)
        universe_selector = ValueScreen('UNIVERSE_SELECTOR', 'Choix Univers', self,
                                        self.panel.start_universe, 0, math.inf)
        channel_selector = ValueScreen('CHANNEL_SELECTOR', 'Choix Adresse', self,
                                       self.panel.start_channel+1, 1, DMX_UNIVERSE_SIZE)
        blackout = ToggleScreen('BLACKOUT', 'Blackout', self)
        test_pattern = MacroScreen('TEST_PATTERN', 'Test leds', self,
                                   macros.TestPixels(panel.columns, panel.rows))
        ip_info = InformationScreen('IP_INFO', 'Adresse IP', self, get_ip_address())

        universe_selector.setCallback(lambda uni: self.panel.setAddress(universe=uni))
        channel_selector.setCallback(lambda chan: self.panel.setAddress(channel=chan))
        blackout.setCallback(lambda off: self.panel.setOnOff(not off))

        home.addChild(main_menu)

        main_menu.addChild(universe_selector)
        main_menu.addChild(channel_selector)
        main_menu.addChild(manual_menu)
        main_menu.addChild(ip_info)

        manual_menu.addChild(blackout)
        manual_menu.addChild(test_pattern)

        self.current = home

        with self.lcd_lock:
            self.lcd = CharLCD(i2c_expander='PCF8574', address=0x3F, cols=20, rows=4,
                               auto_linebreaks=False, backlight_enabled=False)

            self.lcd.cursor_mode = 'hide'

            # UP/DOWN arrow. Use as char \x00
            self.lcd.create_char(0, (
                0b00100,
                0b01110,
                0b11111,
                0b00000,
                0b00000,
                0b11111,
                0b01110,
                0b00100
                ))

            self.updateScreen()
            #self.backlightOn()

    def listenToGPIO(self):
        for pin in [UP_BUTTON, DOWN_BUTTON, OK_BUTTON, BACK_BUTTON]:
            GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
            GPIO.add_event_detect(
                pin, GPIO.RISING,
                callback=self.getGPIOCallback(),
                bouncetime=200
                )

    def getGPIOCallback(self):
        def GPIOCallback(channel):
            with self.gpio_lock:
                GPIO.output(STATUS_LED, GPIO.HIGH)
                #self.backlightOn()

                if channel == UP_BUTTON:
                    print("UP", channel)
                    self.current.onUp()
                elif channel == DOWN_BUTTON:
                    print("DOWN", channel)
                    self.current.onDown()
                elif channel == OK_BUTTON:
                    print("OK", channel)
                    self.current.onOK()
                elif channel == BACK_BUTTON:
                    print("BACK", channel)
                    self.current.onBack()
                self.updateScreen()

                GPIO.output(STATUS_LED, GPIO.LOW)
        return GPIOCallback

    def backlightOn(self):
        self.on_time = datetime.now()
        with self.lcd_lock:
            self.lcd.backlight_enabled = True
        self.panel.threadSafeSchedule(
            11*1000,
            self.turn_off_backlight_if_inactivity
            )

    def turn_off_backlight_if_inactivity(self):
        if datetime.now() - self.on_time >= timedelta(seconds=10):
            with self.lcd_lock:
                self.lcd.backlight_enabled = False

    def updateScreen(self):
        self.current.computeDisplay()

        with self.lcd_lock:
            self.lcd.clear()
            self.lcd.write_string(self.current.first_line)
            self.lcd.crlf()
            self.lcd.write_string(self.current.second_line)

    def cleanup(self):
        GPIO.cleanup()
        with self.lcd_lock:
            self.lcd.close(clear=True)
예제 #5
0
from RPLCD.i2c import CharLCD

lcd = CharLCD('PCF8574', 0x27)  #I2C Adapter model
lcd.write_string('Hello')  # Hello print
lcd.crlf()  # 1 line space
lcd.write_string('World')
예제 #6
0
class vlcd:
    TEXT_FIELD = 0
    DATA_FIELD = 1
    LOADING_CHAR = '.'

    def __init__(self,chip_set='PCF8574',max_rows=2,max_cols=16,ic2Address=0x27):
        self._chip_set = chip_set
        self._address = ic2Address
        self._max_rows = max_rows
        self._max_cols = max_cols
        self._data_bar = 0
        
        self._lcd = CharLCD(self._chip_set, self._address)

        self.play_searching("VCOMPY v1.0",char='+')
        sleep(0.1)
    
    def clear():
        self._lcd.clear()


    def write_centred(self,text):
        length = len(text)
        cur_pos = 0

        if length > self._max_cols or length < 0:
            return False
        delta = self._max_cols - length
        if delta != 0:
            cur_pos = int(floor(delta / 2))

        self._lcd.cursor_pos = (self.TEXT_FIELD,cur_pos)
        self._lcd.write_string(text)
        self._lcd.crlf()

        return True

    def write_left(self,text):
        length = len(text)
        cur_pos = 0

        if length > self._max_cols or length < 0:
            return False
        self._lcd.cursor_pos = (self.TEXT_FIELD,cur_pos)
        self._lcd.write_string(text)
        self._lcd.crlf()

        return True
    def play_searching(self, msg, delay=0.1,char='.'):
        i = 7
        j = 8
        self.write_centred(msg)
        sleep(0.5)
        while i >= 0:
           self._lcd.cursor_pos = (1,i)
           self._lcd.write_string(char)
           self._lcd.cursor_pos = (1,j)
           self._lcd.write_string(char)
           i -= 1
           j += 1
           sleep(delay)
        self._lcd.clear()
        
        

    def print_loading_bar(self, percent,char='.'):
        if percent >= 100:
            return True
        if percent <= 0:
            return False
        p = int(percent * self._max_cols / 100)
        prev = self._data_bar
        self._data_bar = p
        if p - prev < 0:
            print(p)
            self._lcd.home()
            self._lcd.cur_pos = (1,p-1)
            self._lcd.write_string("-")
        s = ""
        i = 0
        
        self._lcd.cur_pos = (1, 0)
        
        while i < p:
            s = s + char
            i += 1
        self._lcd.write_string(s)
        return False