Easy-Python  1.00.00Change to: 中文
class_8 : Light Detect

This is an example of how to use the SAR-ADC to detect the light brightness, and control LED according to light brightness.
If the data from ADC is below 60, the LED will be light.
If the data from ADC is above 60, the LED will be dark.

Reference Modules :
ADC Module.
LED Module.
Example Code :
from machine import ADC
from machine import LED
import utime
light = ADC(4)
led = LED(2)
try:
while True:
if light.read() < 60:
led.on()
else :
led.off()
utime.sleep_ms(100)
finally:
light.deinit()
led.off()