5% OFF Over $19, Code: Elephant5; 10% OFF Over $59, Code: Elephant10

Microbit-Python Course 6.9 Small fan

Posted by Fiona Su on

Microbit-Python Course 6.9 Small fan

Learning goals:

This lesson learns to use the Python language to program the fan motor to turn. After pressing the A button, the fan starts to rotate and there is an animation of the fan turning on the dot matrix.


from microbit import *
fun1 = Image("00990:90900:99999:00909:09900")
fun2 = Image("99009:09099:00900:99090:90099")
all_fun = [fun1, fun2]
while True:
    if button_a.is_pressed():
      while True:
          display.show(all_fun, delay=100)

Programming and downloading

1.You should open the Mu software, and enter the code in the edit window, , as shown in Figure 9-1.

Note! All English and symbols should be entered in English, and the last line must be a space.


Figure 9-1

2. As shown in Figure 9-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 9-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 9-3.


Figure 9-3

4. About wiring


image.png Figure 9-4

5. After the download is successful, we can see a heart on the micro:bit dot matrix, as shown in Figure 9-5. When the A button is pressed, the fan starts to rotate, and an animation of the fan rotation appears on the dot matrix, as shown in Figure 9- 6, 9-7.

image.png Figure 9-5


 Figure 9-6                                                                         Figure 9-7

 The code of the experiment: 9.Small fan.rar

Buy Yahboom Croco:kit sensor starter kit for micro:bit



Leave a comment

Please note, comments must be approved before they are published