from machine import Pin, ADC, PWM
from picozero import PWMLED
from utime import sleep
from math import pow
led1 = PWMLED(15)
light_sensor1 = ADC(26)
led2 = PWMLED(17)
light_sensor2 = ADC(27)
GAMMA = 0.7
RL10 = 50
ADC_VREF = 3.3
#function to convert ADC reading to illumentation (LUX)
def calc_lux(reading):
ldrVoltage = reading / 65536 * ADC_VREF
ldrResistance = 10000 * ldrVoltage / (1 - ldrVoltage / ADC_VREF)
print (ldrResistance)
ldrLux = 5*pow(RL10 * 1000 * pow(10, GAMMA) / ldrResistance, (1 / GAMMA));
return ldrLux
while True:
reading = light_sensor1.read_u16()
lux = calc_lux(reading)
print(lux)
if (lux > 250):
led1.brightness = 512
else:
led1.off()
reading = light_sensor2.read_u16()
lux = calc_lux(reading)
print(lux)
if (lux > 250):
led2.brightness = 512
else:
led2.off()
sleep(1)