from machine import Pin, SoftI2C,ADC # I2C / SPI / UART : Protocoles de communication en IOT
import time
import dht
from ssd1306 import SSD1306_I2C
sys=Pin(17,Pin.IN,Pin.PULL_UP)
sensor = dht.DHT22(Pin(14))
light_sensor=ADC(12)
i2c=SoftI2C(scl=Pin(22), sda=Pin(21), freq=400000)
width, height= 128, 64
oled = SSD1306_I2C(width,height, i2c)
while 1:
reading=sys.value()
while reading==0:
oled.text("Robotic ", 20,10)
sensor.measure() #5adamt l capteur
temperature = sensor.temperature()
time.sleep_ms(50)
humidity= sensor.humidity()
light =(100*(65535- light_sensor.read_u16()))//65535
ch="T: ",str(temperature),"/n","H: ",str(humidity)
oled.text(f'T: {temperature}', 0,30)
oled.text(f'H:{humidity}', 0,40)
oled.text(f'L:{light}', 0,50)
oled.show()
time.sleep_ms(1)
oled.fill(0)
if(light>30):
oled.invert(True)
else:
oled.invert(False)
break;