import time
from machine import Pin, I2C
import dht
from ssd1306 import SSD1306_I2C

i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
oled_width = 128
oled_height = 64
oled = SSD1306_I2C(oled_width, oled_height, i2c)

sensor = dht.DHT22(Pin(26))
while True:
    time.sleep(2)
    sensor.measure()
    temp=sensor.temperature()
    hum=sensor.humidity()
    oled.fill(1)
    oled.text("Temperatura:", 0, 0, 0)
    oled.text("{:.1f} C".format(temp), 0, 10, 0)
    oled.text('Humedad:', 0, 30, 0)
    oled.text("{:.1f}%".format(hum), 0, 40, 0)
    oled.show()
    time.sleep(2)
    oled.fill(0)
    oled.text("Temperatura:", 0, 0, 1)
    oled.text("{:.1f} C".format(temp), 0, 10, 1)
    oled.text('Humedad:', 0, 30, 1)
    oled.text("{:.1f}%".format(hum), 0, 40, 1)
    oled.show()




#oled.rect(0, 0, 128, 64, 1)
#oled.vline(5, 10, 49,1)