from machine import Pin, I2C
from ssd1306 import SSD1306_I2C
from time import sleep
from servo import Servo
import dht
from ssd1306 import SSD1306_I2C
i2c=I2C(0,sda=Pin(0), scl=Pin(0), freq=400000)
oled = SSD1306_I2C(128, 64, i2c)
capteur = dht.DHT22(Pin(2))
servo = Servo(17)
bar = [Pin(0, Pin.OUT), Pin(1, Pin.OUT), Pin(2, Pin.OUT), Pin(3, Pin.OUT), Pin(4, Pin.OUT), Pin(5, Pin.OUT), Pin(6, Pin.OUT), Pin(7, Pin.OUT), Pin(8, Pin.OUT), Pin(9, Pin.OUT)]
while True:
capteur.measure()
temperature = capteur.temperature()
humidite = capteur.humidity()
if temperature >= 30 and humidite ==100:
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(1)
bar[9].value(1)
servo.move(0)
oled.text("fermeture", 8, 8)
oled.show()
oled.fill(0)
elif temperature > 20 and temperature < 30 and humidite == 100:
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(1)
bar[8].value(1)
bar[9].value(1)
servo.move(90)
oled.text("semi-ouvert", 8, 8)
oled.show()
oled.fill(0)
elif temperature < 10 and humidite == 100:
bar[0].value(0)
bar[1].value(0)
bar[2].value(0)
bar[3].value(0)
bar[4].value(0)
bar[5].value(1)
bar[6].value(1)
bar[7].value(1)
bar[8].value(1)
bar[9].value(1)
servo.move(180)
oled.text("ouvert", 8, 8)
oled.show()
oled.fill(0)
print('Température:{:.1f}°C'.format(temperature))
print('Humidité:{:.1f}%'.format(humidite))