# dht11_excercise: print humidity and temperature to 2x16 LCD
#    and show humidity and temperature alternated on7z7 segment led
# copyright by Anthony Vogelaar, Perth Scotland
# rev 0.10  2025-08-29  initial release

import	time
from	driver_lcd	import	Lcd
from	drivers		import	Led7, DHT11

# ========================== Test ===========================

# test used peripherals
def test():
    lcd = Lcd()								# lcd test
    lcd.print('Hello')
    lcd.print('   world!')
    led7 = Led7(pin_scl=32, pin_sda=33)		# 7 segment led test
    led7.show(123, 2)
    dht11 = DHT11()							# test DHT11  -->  humidity, temperature
    print(dht11.getHT())

# ======================= Main =============================

class Main():
    
    def __init__(self):
        self.lcd  = Lcd()
        self.led7 = Led7(pin_scl=32, pin_sda=33, i2c_bus=1)
        self.dht11 = DHT11()
        self.run()
        
        
    def showOnLed7(self, value=0):
        self.led7.show(int(value*10), 2)
        
        
    def showOnLcd(self, humidity, temperature):
        self.lcd.print('Humidity   ', humidity)
        self.lcd.print('Temperature', temperature)
        
        
    def run(self):
        while True:
            h, t = self.dht11.getHT()
            self.showOnLed7(h)
            self.showOnLcd(h, t)
            time.sleep(2)
            h, t = self.dht11.getHT()
            self.showOnLed7(t)
            self.showOnLcd(h, t)
            time.sleep(2)
            
#test()
Main()

# =========================== end ===========================
