# 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) #resolución, o sea , regular la precisión de la lectura
# Si es 12 bits su valores son de 0 a 4095, si es bits 11 es desde 0 a 2046
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)