第 1 步:动手吧
它是什么?
有人经常动你的存钱罐吗? 来制作你的 BBC micro:bit 程序使其发送警报让你知道! 你将学习选择、比较逻辑和 micro:bit 的光线传感器。
这两个视频向你展示了你将制作什么以及如何编程
工作原理
- 这个程序会使用 micro:bit’s LED 的光线传感器.
- 把你的 micro:bit 放进你想保护的罐子里。 当盖打开时,光线传感器检测到光照亮度的变化并触发报警。
- 该程序使用一个循环来持续检测光照亮度。
- Selection ('if... else') and comparison logic (> 30) are used so that if the light level is above a certain amount, an angry face appears on the display; else, it clears the screen.
所需材料
- micro:bit或者是MakeCode模拟器
- MakeCode编辑器
- 电池盒
- 我们的设置指南会对你有所帮助
第 2 步:编程
第3步:完善
- Adjust the program, removing the "else" part of the comparison, so that the angry face remains on the micro:bit’s display whatever the light level so that you can tell someone has opened your tin.
- Add an audible alarm using blocks from the music section of the MakeCode editor.
- Count how many times your tin has been opened by introducing a variable into the program.
- If you have two micro:bits, use the radio function to send you a signal as soon as your tin has been opened. Take a look at the light alarm project to find out how to do this.