夜灯

您所在的位置:网站首页 小夜灯原理是什么 夜灯

夜灯

#夜灯 | 来源: 网络整理| 查看: 265

第 1 步:制作它是什么?

A nightlight that lights up your BBC micro:bit’s LED display in the dark.

介绍编程指南

This project uses the micro:bit’s LEDs as a light sensor input to make a light that switches on automatically when it gets dark.

The micro:bit’s light sensor measures light in a range from 0 (very dark) to 255 (very bright).

工作原理An infinite loop in the code keeps the micro:bit checking light levels.It uses logic to decide whether to turn the LEDs on or off. A conditional instruction (if… then… else) makes the decision to turn the LED lights on or off.If the light level falls below 100, then it lights up the LEDs on the micro:bit’s display. Else (otherwise), it clears the screen to turn the LED lights off.Test it out by covering the display or shining a light on it, and see if the LEDs light up when it’s dark.You may need to change the 100 number depending on the light levels around you. Larger numbers will make the light come on more easily. Smaller numbers will make the light only come on when it’s very dark.所需材料micro:bit或者是MakeCode模拟器MakeCode 或者 Python 编辑器电池盒(选配)光源和覆盖micro:bit的东西第 2 步:编程

Loading...

在课堂中打开在 MakeCode 中打开下载 HEX1from microbit import * 2 3while True: 4 if display.read_light_level() < 100: 5 display.show(Image( 6 "99999:" 7 "99999:" 8 "99999:" 9 "99999:" 10 "99999")) 11 else: 12 display.clear() 13 sleep(2000) 14在课堂中打开在 Python 中打开下载 HEX第3步:完善更改图像以在黑暗的环境下显示月亮或星星。将micro:bit装在你的包包或衣服上,以在步行或骑自行车时将其用作额外的安全灯 – 你能否使其闪烁以加强效果?Try this MakeCode project that makes the LED display get lighter and darker depending on the amount of light falling on the micro:bit. 你还能在其他地方看到以这种方式对光做出反应的事物吗?


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3