Skip to content

활동

Festive decoration

초급 | MakeCode | LED, 빛 센서, 사운드 | 반복 실행, 센서

1단계: 만들어 보세요.

프로젝트 소개

Turn your micro:bit into a festive decoration that shows a flashing star on the LED display as soon as it gets dark.

다음 동영상을 통해 만들고 프로그래밍하는 방법을 살펴보세요.:

설명

  • The program uses the micro:bit’s light sensor to measure the light levels.
  • 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. This creates the animation.
  • A forever loop in a computer program is an instruction that repeats forever.
  • If the light levels are more than 100, the micro:bit is told to clear the screen.

준비물

  • micro:bit (또는 MakeCode 시뮬레이터)
  • MakeCode 편집기
  • 배터리 팩(선택 사항, 있으면 좋음)
  • our set-up guide may be useful

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!