from machine import Pin, ADC
from machine import I2C
import ssd1306
from time import sleep
i2c = I2C(scl=Pin(22), sda=Pin(21))
oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)
ldr = ADC(Pin(34))
ldr.atten(ADC.ATTN_11DB)
led = Pin(13, Pin.OUT)
while True:
val_ldr = ldr.read()
oled.fill(0)
oled.text("Iluminacion: ", 14, 10)
oled.text(str(val_ldr), 50, 30)
umbral = 500
if val_ldr < umbral:
led.on()
else:
led.off()
oled.show()
sleep(1)