Skip to content

アクティビティ

ダンスのステップ

初級 | MakeCode, Python | LED表示, ボタン | ダンス, 反復処理

ステップ1: 作る

説明

回数を指定した繰り返し順次処理を使って、BBC micro:bit上でダンスの振り付けを作りましょう。 このプロジェクトは一人でも友達とでも使えます。

この2つのビデオで、何を作り、どのようにコーディングするかご案内します。

動作の仕組み

  • Aボタンを押すとプログラムが始まります。
  • micro:bitのLEDディスプレイに矢印が表示され、ダンスのステップを指示してくれます。にステップ、にステップ、両手をげて、最後に
    の床を指さす。
  • 複数人で使う場合は、皆で同時にmicro:bitのAボタンを押すことで、同時にダンスの振り付けを開始し、一致させることができます。
  • 各画像を表示した後、プログラムは1秒間(1000ミリ秒)、次の画像を表示する前に 一時停止 します。 一時停止は、みんなが時間をキープするのに役立ちます。
  • 一連のダンスの振り付け が4回繰り返され、その後停止します。 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. これは イテレーションとも呼ばれます。 
  • ルーティンが終了すると、micro:bitのLEDディスプレイが消去されます。

必要なもの

ステップ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.