Skip to content

活动

Dance steps

初学者 | MakeCode, Python | LED显示器, 按钮 | 舞蹈, 迭代

第 1 步:制作

它是什么?

Use count-controlled loops and a sequence to help create a dance routine project on your BBC micro:bit. You can use the project alone or with friends.

这两个视频介绍了你将制作什么以及如何编程:

工作原理

  • The program starts when you press button A.
  • Arrows appear on the micro:bit’s LED display, which tell you how to dance – step left then right, put your hands up in the air, then point down to the floor.
  • If you are using the project in a group, everyone should press button A on their micro:bits at the same time, so that you start the dance routine at the same time and remain in sync.
  • After showing each image, the program pauses for a second (1000 milliseconds) before showing the next image. The pause helps everyone to keep in time.
  • The sequence of dance moves repeats four times then stops. The sequence is kept going using a count-controlled loop. Count-controlled loops repeat instructions a set number of times.
  • Using loops to keep things happening is an important idea in computer programming. This is also called iteration
  • When the routine is finished, the micro:bit’s LED display is cleared.

所需材料

第 2 步:编程

1# Imports go at the top
2from microbit import *
3
4
5while True:
6    if button_a.is_pressed():
7        for i in range(4):  
8            display.show(Image('00900:'
9                       '09000:'
10                       '99999:'
11                       '09000:'
12                       '00900'))
13            sleep(1000)
14            display.show(Image('00900:'
15                       '00090:'
16                       '99999:'
17                       '00090:'
18                       '00900'))
19            sleep(1000)
20            display.show(Image('00900:'
21                       '09990:'
22                       '90909:'
23                       '00900:'
24                       '00900'))
25            sleep(1000)
26            display.show(Image('00900:'
27                       '00900:'
28                       '90909:'
29                       '09990:'
30                       '00900'))
31            sleep(1000)
32    display.clear()
33

第3步:完善

  • Make instructions for other dance sequences to appear when you use other inputs such as pressing button B or shaking the micro:bit.
  • Change the length of the pauses to make the program run in time with your favourite song.
  • Use this project alongside the step counter project to monitor how well you dance.