# Sensor de luminosidad con Fotoresistencia - LDR
# https://youtu.be/Wn-lq8GyK0U?list=PLV2our4ryD2qGic2r5PccRs92xJ38ONC7
# https://docs.wokwi.com/parts/wokwi-photoresistor-sensor
# Sale del A0(analog output) del sensor al 34 del esp32. También tiene el D0(digital output) del
# sensor(aporta 1 o 0), pero no lo uso.
# The ADC class to read analog value, and the PWM class to generate PWM signals.
'''
The voltage on the AO pin depends on the illumination - that is the amount of light that
falls on the sensor. You can read this voltage by connecting the AO pin of the
photoresistor sensor to an analog input pin and then using the analogRead() function.
'''
from machine import Pin,ADC
import utime
sensor=ADC(Pin(34))
sensor.atten(ADC.ATTN_11DB)# atenuación
sensor.width(ADC.WIDTH_12BIT)
led=Pin(2,Pin.OUT)
while True:
medicion=int(sensor.read()) # entre 0 y 4095
print("Medición: ", medicion)
utime.sleep(0.5)
if medicion >= 1000:
led.value(1)
else:
led.value(0)