Skip to content

活动

Get up!

初学者 | MakeCode, Python | LED显示器, 光传感器, 声音 | 传感器, 数字 & 位置值 , 迭代, 选择

第 1 步:制作

它是什么?

Turn your micro:bit into a light-sensitive alarm to help you get up in the morning. You'll learn how to use infinite loops, and selection with comparison logic.

这两个视频向你展示了你将制作什么以及如何编程

工作原理

  • The program uses the micro:bit’s LED display as a light sensor.
  • Selection ('if... else') and comparison logic (> 70) are used so that if the light level is above a certain amount, a sun icon appears and it makes a noise; else, it clears the screen.
  • If the light level is greater than (>) 70, a sun appears on the LED display, telling you it’s time to get up.
  • The program uses an infinite loop to keep sensing the light level.
  • You can adjust the threshold at which the sun appears. Use larger numbers to make it less sensitive to light, so the alarm only goes off when it's brighter - or smaller numbers to make it more sensitive to light.

所需材料

  • micro:bit (or use the simulator in the online editors)
  • MakeCode 或者 Python 编辑器
  • 电池组(推荐,可选)

第 2 步:编程

第3步:完善

  • Change the alarm sound.
  • Replace the sun icon with motivational messages that can help you to start your day.