Welcome to Mini Microbit Handle repository
8.Morning and night
8.Morning and night
1. Learning goals
In this lesson, we will learn to how to make micro:bit display different patterns according to external light.
2.Code and analysis
from microbit import *
This code is to import everything from the microbit library, and any program need to uses import this library.
display.read_light_level()
In reverse bias mode, use the LED light of microbit dot matrix to sense the brightness falling on the dot matrix. Returns an integer between 0 and 255.
Micro:bit has a dot matrix of 5*5 LEDs, and the brightness of each LED on the dot matrix can be set to a value from 0 to 9.
If the brightness of an LED is set to 0, then it goes out.
If its brightness is set to 9, then it is at the brightest level.
We can display a custom image on the micro:bit dot matrix. Based on the pattern required this time, we define four custom patterns and display this pattern.
Note:
1 - The capital letter/lowercase letters must be distinguished!
2 - Correct spelling!
3 - Keywords such as # need a space between the content.
4 - You can only use the Tab key (tabulation key) for indentation.
3. Programming and downloading
3.1 You should open the Mu software, and enter the code in the edit window, , as shown in figure .
Note! All English and symbols should be entered in English, and the last line must be a space.
3.2 As shown in figure, you need to click the Check button to check if our code has an error. If a line appears with a cursor or an underscore, the program indicating this line is wrong.
3.3 You need to connect the micro data cable to micro:bit and the computer, then click the Flash button to download the program to micro:bit as shown in figure.
4. Experimental phenomena
After the program is successfully downloaded.
When the micro:bit board is in a relatively bright environment, a sun pattern will be displayed on the dot matrix, which means to say "Good morning" to everyone.
When the micro:bit board is in a relatively dark environment, a moon pattern will appear on the dot matrix, which means to say "Good night" to everyone.