1. Learning goals
In this lesson, we will learn to use the on board buzzer and photosensitive sensor of the micro:bit to detect the current light intensity in real time.
When the light is dark, the Micro:bit board dot matrix will display a moon.
When the Micro:bit board light is strong, it means daytime, start the alarm clock, the Micro:bit board dot matrix will display a sun.
2. Mode 1 online programming:
First, we need to connect the micro:bit to the computer by USB cable. The computer will pop up a USB flash drive and click on the URL http://microbit.org/ in the USB flash drive to enter the programming interface to start program.
Mode 2 offline programming:
We need to open the offline programming software. After the installation is complete, enter the programming interface, click【New Project】, you can start program.
3.Looking for blocks
The following is the location of the building blocks required for this programming.
4.Combine block
The summary program is shown below.
Program analysis:
Set the light level value to the variable “item”.
When the condition is met (“item” is less than or equal to 20), it means that the current environment has weak light intensity and it is at night, and the dot matrix displays a moon.
Otherwise, it means that the current ambient light intensity is strong, the dot matrix displays the sun, and the buzzer starts to play music.
5.Experimental phenomena
After connecting the computer to the micro:bit board via the micro USB data cable. Click download or save on the programming interface, and the program can be successfully downloaded to the Micro:bit board.
When current environment has weak light intensity and it is at night, and the dot matrix displays a moon.
When current ambient light intensity is strong, the dot matrix displays the sun, and the buzzer starts to play music.