Skip to content

활동

Water bottle alert

초급 | MakeCode, Python | 가속도 센서 | 건강

1단계: 만들어 보세요.

프로젝트 소개

Turn your BBC micro:bit into a water bottle alert, so you can tell if someone else has drunk from it. You will learn how to use the micro:bit's LED display and accelerometer.

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

설명

  • The micro:bit shows a heart on its LED display when your water bottle is upright.
  • The LED display shows a warning cross when a tilt is detected by the micro:bit’s accelerometer. The cross stays there until you reset the program by pressing the reset button on the back of the micro:bit or by disconnecting and reconnecting the battery.
  • An accelerometer measures forces in three dimensions, including gravity, so your projects can tell which way up your micro:bit is.

준비물

  • micro:bit (또는 MakeCode 시뮬레이터)
  • MakeCode 편집기
  • battery pack

2단계: 프로그래밍 해보세요.

1# Imports go at the top
2from microbit import *
3
4display.show(Image.HEART)
5sleep(400)
6
7while True:
8    if accelerometer.was_gesture('right'):
9        display.show(Image.NO)
10

3단계: 더 좋게 만들어 보세요.

  • Find a way to reset the program without using the micro:bit’s reset button, for example by pressing button A or B to show a heart icon.
  • Add an audible alarm using blocks from the music section of the MakeCode editor.