Open 4.2Automatic_lighting.py and click .
'''
* Filename : Automatic_lighting
* Thonny : Thonny 4.1.4
* Auther : http//www.keyestudio.com
'''
from machine import Pin,ADC
import time
led = Pin(11,Pin.OUT)
Photores = ADC(27)
while True:
Photores_Value = Photores.read_u16()
print('ADC Value:',Photores_Value)
if (Photores_Value < 10000):
led.on()
else:
led.off()
time.sleep(0.1)
Conceive:
Initialization: set the pins of LED module and the photoresistor.
Loop:
① read the value of photoresistor and print it on Shell.
② Determine whether the value id less than 10000(the threshold can be changed according to needs).
If the value is less than 10000, LED will be on.
If the value equals or is greater than 10000, LED will go off.