Learning goals:
In this lesson, we will learn the using of a single pin. When we clamp the GND with one end of the alligator clip and the pin0 pin with the another end of the alligator clip, the micro:bit dot matrix will display smile expression, Otherwise micro:bit dot matrix will display sad expression.
Code:
from microbit import*
while True:
if pin0.is_touched():
display.show(Image.HAPPY)
else:
display.show(Image.SAD)
Programming and downloading:
1.You should open the Mu software, and enter the code in the edit window, , as shown in Figure 7-1.
Note! All English and symbols should be entered in English, and the last line must be a space.
Figure 7-1
2. As shown in Figure 7-2, 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.
Figure 7-2
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 7-3.
Figure 7-3
4. After the download is complete, you can see that the sad expression on the micro:bit dot matrix, as shown in Figure 7-4. When we clamp the GND with one end of the alligator clip and the pin0 pin with the another end of the alligator clip, the micro:bit dot matrix will display smileexpression, as shown in Figure 7-5.
Figure 7-4 Figure 7-5
The code of the experiment: 6.Do not touch me.zip
Micro Python Basic Course
- Micro Python Basic Course 1.Hello,World
- Micro Python Basic Course 2: Display built-in image
- Micro Python Basic Course 3: Display custom image
- Micro Python Basic Course 4: Display custom animation
- Micro Python Basic Course 5: Button game
- Micro Python Basic Course 6: Do not touch me
- Micro Python Basic Course 7: Play built-in music
- Micro Python Basic Course 8: micro:bit voice talk