Skip to content

アクティビティ

ジュークボックス

初級 | MakeCode, Python | スピーカー, ボタン, 端子, | ハードウェア & ソフトウェア, 入出力,

ステップ1: 作る

説明

ボタンを押すだけで、色々な曲を流す音響機器を作ってみましょう。

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

はじめに

プログラミングガイド

動作の仕組み

  • ジュークボックスはコインを入れてボタンを押し、聞きたい曲を選択して色々な曲を聞くことができる機器です。
  • This micro:bit jukebox uses the A and B button inputs to play different built-in tunes.
  • If you have a micro:bit V2 with built-in speaker, you'll hear the sound straight away. You can also attach headphones to any micro:bit using crocodile clip leads:
micro:bitのP0端子に接続されたヘッドフォンプラグの先端部分、micro:bitのGND端子に接続されたヘッドフォンプラグの長い部分
  • micro:bitのP0端子をヘッドフォンプラグの先端に、GND端子をヘッドフォンプラグの長い部分に接続します。
  • micro:bitを使って音を鳴らす時、P0端子が出力になります。

必要なもの

  • micro:bit(またはMakeCodeシミュレーター)
  • MakeCodeまたはPythonエディター
  • バッテリーパック(オプション)
  • a pair of headphones and two crocodile clip leads (optional)

ステップ2: プログラムする

1from microbit import *
2import music
3
4while True:
5    if button_a.was_pressed():
6        music.play(music.ODE)
7    if button_b.was_pressed():
8        music.play(music.BLUES)
9

ステップ3: 改善する

  • 曲を「プレリュード」や「ジ・エンターテイナー」に変更してみましょう。 You can find a list of all the built-in tunes you can use in Python here.
  • 選択した曲によって異なるマーク、文字、数字や単語を表示してみましょう。
  • Make it play a different tune if you shake it, press buttons A and B at the same time, or press the micro:bit's touch logo.