from machine import Pin,I2C
from time import sleep 
import dht 
from servo import servo 
#variables 
ct = dht.DHT22(Pin(28))
s = servo (22)
i2c=I2C(0,sda=Pin(0),scl=Pin(1),freq=40000)
oled = SSD1306_I2C(128,64,I2C)
bar  = [Pin(5, Pin.OUT),Pin(7, Pin.OUT),Pin(8 ,Pin.OUT),Pin(9, Pin.OUT),Pin(14, Pin.OUT),Pin(10, Pin.OUT),Pin(11, Pin.OUT),
Pin(12, Pin.OUT),Pin(13, Pin.OUT),]
led_rouge = Pin(19, Pin.OUT)
led_verte = Pin(26, Pin.OUT)
while True: 
    ct.measure()
    t = ct.temperature()
    h = ct.humidity()
    print('Température:{:.1f}°C'.format(temperature))
    print('Humidité:{:.1f}%'.format(humidite))
    
    
    if t >=30:
       bar[0].value(0)
       bar[1].value(0)
       bar[2].value(0)
       bar[3].value(0)
       bar[4].value(0)
       bar[5].value(0) 
       bar[6].value(0)
       bar[7].value(0)
       bar[8].value(0)
       bar[9].value(0)
       servo.mouve(0)
       servo .mouve 
       oled.texte()
       oled.show() 
       oled.fill(0)
    # en dessous de 20°
    if temperature < 20 and (humidite) == 50:
       s.move(0)  # Servo reste à 0°
    
    print("Température basse et humidité correcte")
    if 25 <= t <= 30:
        s.move(90)
    
        
    print("Température modérée")
    sleep(2)
    #plus de 30°C
    if temperature > 30:
       s.move(180)
    print("Température élevée")
    sleep(1)
    
    if temperature>= 30 and humidité == 100: 
        led_rouge.value(1)
       
    if temperature >20 and temperature <30 and humidité == 100:
        led_verte.value(1)
     
    print  temperature < 10 humidité == 100:
         5 led s'allument