Skip to content

アクティビティ

Festive decoration

初級 | MakeCode | LED表示, 光センサー, | センサー, 反復処理

ステップ1: 作る

説明

あなたのmicro:bitを、暗くなったらLEDディスプレイに点滅する星を表示するお祝いの飾りにしましょう。

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

動作の仕組み

  • このプログラムではmicro:bitの明るさセンサーを使って光の強さを測っています。
  • It then uses an “if then else” logic block.
  • If the light levels are less than 100, the micro:bit is instructed to show two icons – a large star then a small star with pauses in between – in a forever loop on the LED display. これによってアニメーションが作られます。
  • A forever loop in a computer program is an instruction that repeats forever.
  • もし明るさのレベルが100を超えた場合、micro:bitは画面をクリアします。

必要なもの

  • micro:bit(またはMakeCodeシミュレーター)
  • MakeCodeエディター
  • バッテリーパック(任意ですが推奨)
  • 私たちのセットアップガイドが役に立つでしょう

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

1# Imports go at the top
2from microbit import *
3
4while True:
5    if display.read_light_level() < 100:
6        display.show(Image('90909:'
7                           '09990:'
8                           '99999:'
9                           '09990:'
10                           '90909'))
11        sleep(500)
12        display.show(Image('00000:'
13                       '09090:'
14                       '00900:'
15                       '09090:'
16                       '00000'))
17        sleep(500)
18    else: display.clear()
19    sleep(500)
20   

ステップ3: 改善する

  • Adjust the threshold at which the animation plays to better suit your room.
  • Instruct your micro:bit to play a festive sound on pressing button A.
  • Make other festive projects such as a jukebox which plays festive tunes, or an alarm which comes on when Father Christmas arrives on Christmas Eve!