from machine import Pin, I2C, SoftI2C, ADC
from dht import DHT11
import time
import ssd1306
#OLED setup
i2c = SoftI2C(scl=Pin(22), sda=Pin(21), freq=400000)
display = ssd1306.SSD1306_I2C(128, 64, i2c)
#DHT initial
dht = DHT11(Pin(15))
while True:
dht.measure() # start to measure
#temp = dht.temperature() # return the temperature
#humid = dht.humidity() # return the humidity
for i in range(10):
temp = i
humid = 10 - i
temp_str = f"Temp: {temp}"
humid_str = f"Himid: {humid}"
display.fill(0) # 填充螢幕 0 = 全黑, 1 = 全亮
display.text(temp_str, 0, 0, 1)
display.text(humid_str, 0, 1*8+2, 1)
display.show()
time.sleep(0.5)