BBC micro:bit|Science/定时闸门-计算汽车速度
【BBC micro:bit】Science/定时闸门-计算汽车速度本文转自micro:bit官方网站翻译kiki 未经许可请勿转载定时门/Timing gates
将两个门链接到micro:bit,就可以检测到通过的车辆。
当汽车通过 闸门0 时,它通过 on pin pressed 发送一个事件到micro:bit。micro:bit在变量中记录时间t0。
当车通过 闸门1 的时候,它通过 on pin pressed 发送一个事件到micro:bit。micro:bit在变量中记录时间t1。
其余的是一些数学和物理知识。穿过门的时间计算为t1-t0。通过将门之间的距离除以持续时间,我们得到了车的速度!
物料/Materials
[*]纸板
[*]铝箔
[*]双面胶带
[*]4个鳄鱼夹
[*]micro:bit和USB线
代码
一:显示LED
在LED屏幕上显示图片
参数
leds是一个字符串,用于控制打开和关闭哪些LED。
interval是一个可选数字,表示显示图片后等待多少毫秒。如果使用块编程,interval则设置为400毫秒。
例
该程序显示具有该show leds功能的图片。
二:On Pin Pressed
参数
let count = 0
basic.showNumber(count, 100)
input.onPinPressed(TouchPin.P0, () => {
count = count + 1
basic.showNumber(count, 100)
})
三:在变量中存储数字
let item = 5
basic.showNumber(item)
在变量中存储字符串
let name = "Joe"
basic.showString(name);
四:运行时间
示例:已用时间
input.onButtonPressed(Button.B, () => {
let now = input.runningTime()
basic.showNumber(now)
})
五:事件时间戳
六:显示数字
显示号码
例子:
要显示数字10:
basic.showNumber(10)
要显示存储在变量中的数字:
let x = 1
basic.showNumber(x)
示例:计数到5
for (let i = 0; i < 6; i++) {
basic.showNumber(i)
basic.pause(200)
}
建造大门
https://v.qq.com/x/page/w0837ops2jm.html
升级汽车
https://v.qq.com/x/page/k0837ovvw01.html
用代码检测汽车
basic.showLeds(`
. . . . .
. . . . .
. . # . .
. . . . .
. . . . .
`)
input.onPinPressed(TouchPin.P0, () => {
basic.showLeds(`
# . . . .
# . . . .
# . . . .
# . . . .
# . . . .
`)
})
检测第二个门
basic.showLeds(`
. . . . .
. . . . .
. . # . .
. . . . .
. . . . .
`)
input.onPinPressed(TouchPin.P0, () => {
basic.showLeds(`
# . . . .
# . . . .
# . . . .
# . . . .
# . . . .
`)
})
input.onPinPressed(TouchPin.P1, () => {
basic.showLeds(`
# . . . #
# . . . #
# . . . #
# . . . #
# . . . #
`)
})
计算时间
let t0 = 0;
let t1 = 0;
basic.showLeds(`
. . . . .
. . . . .
. . # . .
. . . . .
. . . . .
`)
input.onPinPressed(TouchPin.P0, () => {
t0 = control.eventTimestamp();
basic.showLeds(`
# . . . .
# . . . .
# . . . .
# . . . .
# . . . .
`)
})
input.onPinPressed(TouchPin.P1, () => {
t1 = control.eventTimestamp();
basic.showLeds(`
# . . . #
# . . . #
# . . . #
# . . . #
# . . . #
`)
let d = t1 - t0
basic.showNumber(d)
})
计算速度
测量门之间的距离并应用牛顿定律来计算汽车的速度(它的速度)。
v = d / t
赞一下KIKI,多译一些科学探究的过来学。:call: rzyzzxw 发表于 2019-2-12 18:51
赞一下KIKI,多译一些科学探究的过来学。
好的呢 很好的科学探究赞:handshake {:5_118:}哈哈哈哈
不错 太感谢了 实用哦 确實很有用 謝謝老師分享 厉害厉害 很实用,赞赞赞! 厉害厉害 不错不错!
页:
[1]