import time
import ssd1360
from machine import Pin, I2C
import dht
led=Pin(26,Pin.OUT)
buzzer=Pin(23,Pin.OUT)
dht=dht.DHT22(Pin(19))
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
oled_width = 128
oled_height = 64
oled = ssd1360.SSD1306_I2C(oled_width, oled_height, i2c)
while 1:
  oled.fill(0)
  dht.measure()
  tem=dht.temperature()
  hum=dht.humidity()
  oled.text('temperature: '+str(tem)+"%", 0, 0) # Afficher les deux mots 'Carte ESP32'
  oled.text('humidité: '+str(tem)+"%", 0, 20)
  oled.show()

  if tem<50:
    buzzer.value(1) # Le buzzer sonne
    time.sleep(2) # Attendre 2s
    led.on()
  else:
    buzzer.value(0)
    led.off()