#write a micro python script to interface an LDR with GPIO14 of ESP32 todo the following:-
#1) Read the data from ldr and print the sam on shell window.
#2) calculate the ammount of valtage provided by ldr wrt to the change of light intnsity
#3) control the led connected to GPIO2 of ESP32
#4) control the brightness of the led wrt to intensity of light
from machine import Pin,ADC,PWM
from time import sleep
ldr = ADC(Pin(14))
ldr.width(ADC.WIDTH_10BIT)
ldr.atten (ADC.ATTN_11DB)
led_PWM = PWM(Pin(2),5000)
while 1:
ldr_value = ldr.read()
print("ldr_value is:",ldr_value)
voltage = ldr_value*(3.3/4095)
print("voltage is:",voltage)
led_PWM.duty(1023-ldr_value)
sleep(0.5)