from machine import Pin, SoftI2C , ADC
import time
import dht
sensor=dht.DHT22(Pin(16))
sys=Pin(17 , Pin.IN , Pin.PULL_UP)
light_sensor=ADC(12)
from ssd1306 import SSD1306_I2C
i2c=SoftI2C(scl=Pin(22),sda=Pin(21),freq=400000)
width , height = 128 , 64
y=0
oled = SSD1306_I2C (width , height , i2c)
oled.invert(True)
while 1:
reading = sys.value()
while reading==1:
reading = sys.value()
print(reading)
sensor.measure()
tmp=sensor.temperature()
hum=sensor.humidity()
light=65535-light_sensor.read_u16()
light=int(light*(100/65535))
#print(light)
oled.text(f'tmp:{tmp}C',10,10)
oled.text(f'hum:{hum}%',10,20)
oled.text(f'light{light}%',10,30)
oled.show()
time.sleep_ms(1)
oled.fill(0)
if light<30 :
oled.invert(True)
else:
oled.invert(False)