Programming and note
Analog Read:
Micro:bit uses an
analog read
block to read the value as a 10-digit number
that ranges from 0 to 1023. The
analog read
block is a value based block, Which means
that you have to insert it into a block with a matching shape. In this case, we use this value
and compare it with the value( It indicates that the brightness is bright and we don’t need
to turn on the LED when threshold we set is larger than this value; when it is less than this
value, it indicates that the brightness is dark and we need to turn on the LED).
Download the program to micro:bit to see what happens.
The LED will not light up during the day (in a bright environment). And when
the daylight gradually dims into the night, the LED will light up automatically.
If the LED does not change, try to adjust the threshold you set.
Result
Do you have plants in your home? Did you know that a plant needs light to grow? If
there is no enough light, plants will wither. Let's protect them and think about how to
use this light sensor to solve this problem.
18