from machine import ADC,Pin, Timer
led = Pin (4,Pin.OUT)
LDR = ADC(Pin(32))
GAMMA = 0.7
RL10 = 50
def fun(tim):
if LDR.read() >2000 :
global GAMMA
global RL10
analogValue = LDR.read()
voltage = analogValue / 4096. * 5
resistance = 2000 * voltage / (1 - voltage / 5)
lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA))
led.value(1)
else:
led.value(0)
tim = Timer(0)
tim.init(period = 500,mode = Timer.PERIODIC , callback = fun)