KIKIYA 发表于 2019-2-12 16:44:27

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

rzyzzxw 发表于 2019-2-12 18:51:22

赞一下KIKI,多译一些科学探究的过来学。:call:

KIKIYA 发表于 2019-2-12 18:52:44

rzyzzxw 发表于 2019-2-12 18:51
赞一下KIKI,多译一些科学探究的过来学。

好的呢

rzegkly 发表于 2019-2-13 10:37:14

很好的科学探究赞:handshake

tyjjr 发表于 2019-2-13 15:01:51

{:5_118:}哈哈哈哈

gada888 发表于 2019-2-16 08:42:01

不错

望椰止渴 发表于 2021-1-2 20:53:01

太感谢了

俺是胡胡 发表于 2022-8-12 08:27:48

实用哦

大哥哥 发表于 2022-8-13 13:44:07

确實很有用 謝謝老師分享

花生编程 发表于 2023-8-25 10:20:58

厉害厉害

花生编程 发表于 2023-8-25 10:22:02

很实用,赞赞赞!

三春牛-创客 发表于 2023-8-28 12:05:08

厉害厉害

三春牛-创客 发表于 2023-8-28 12:06:41

不错不错!
页: [1]
查看完整版本: BBC micro:bit|Science/定时闸门-计算汽车速度