from machine import Pin, I2C
import time
from time import sleep
import dht
from servo import Servo
from ssd1306 import SSD1306_I2C
import utime
width = 128
height = 64
i2c = I2C(0, scl = Pin(13), sda = Pin(12), freq = 400000)
oled = SSD1306_I2C(width, height, i2c)
capteur = dht.DHT22(Pin(11))
servo = Servo(pin=27)
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), Pin(10, Pin.OUT)]
while True:
capteur.measure()
temperature = capteur.temperature()
humidite = capteur.humidity()
if temperature >= 30 and humidite == 100:
servo.move(0)
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)
oled.text("zero mouvement", 8,8)
oled.show()
oled.fill(0)
utime.sleep(0.05)
elif temperature > 20 and temperature < 30 and humidite == 100:
servo.move(90)
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)
oled.text("Semi-ouvert", 8,8)
oled.show()
oled.fill(0)
utime.sleep(0.05)
elif temperature < 10 and humidite == 100:
servo.move(180)
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)
utime.sleep(0.05)