2019-1-29 15:52:01 [显示全部楼层]
3307浏览
查看: 3307|回复: 1

[入门教程] BBC micro:bit|SCIENCE|物质的转换

[复制链接]
micro:bit/ SCIENCE/ 物质的转换
本文转自micro:bit官方网站
翻译kiki 未经许可请勿转载
BBC micro:bit|SCIENCE|物质的转换图8
所需时间:
基于对编码概念的熟悉程度,该项目大约需要30-45分钟

物料:
* 纸板
* 铝箔
* 标记笔(红色和黑色)
* 1个micro:bit电池座和2节AAA电池
* 4个鳄鱼夹
不好意思 又要看视频广告了


步骤:
将一块纸板变成湿度和温度的探测器!
* 折叠铝箔纸块,并将它们放在纸板周围。
* 将每片箔连接到micro:bit上的相应引脚。
而已!

代码:
你有没有试过代表物质的状态?让我们尝试在视觉上代表基于大气温度的各种物质状态

第1步:变量

为了使物质遵循大气温度的规则,我们需要添加存储数据的变量。然后我们将分配(设置)变量的值。
我们想要将两(2)个变量命名如下:“atmos_temperature”和“temperature”。将变量的值设置为100.修改代码,使其看起来像这样。
BBC micro:bit|SCIENCE|物质的转换图1
[mw_shl_code=applescript,true]let temperature = 100
let atmos_temperature = 100[/mw_shl_code]

第2步:检测固体
BBC micro:bit|SCIENCE|物质的转换图2
BBC micro:bit|SCIENCE|物质的转换图9

[mw_shl_code=applescript,true]let temperature = 0
let atmos_temperature = 0
input.onPinPressed(TouchPin.P2, () => {
    atmos_temperature = 0
    basic.showString("SOLID")
})
atmos_temperature = 100
temperature = 100[/mw_shl_code]

第3步:检测液体
BBC micro:bit|SCIENCE|物质的转换图3
BBC micro:bit|SCIENCE|物质的转换图10
[mw_shl_code=applescript,true]let temperature = 0
let atmos_temperature = 0
input.onPinPressed(TouchPin.P2, () => {
    atmos_temperature = 0
    basic.showString("SOLID")
})
input.onPinPressed(TouchPin.P1, () => {
    atmos_temperature = 80
    basic.showString("LIQUID")
})
atmos_temperature = 100
temperature = 100[/mw_shl_code]

第4步:检测气体
BBC micro:bit|SCIENCE|物质的转换图4
BBC micro:bit|SCIENCE|物质的转换图11
[mw_shl_code=applescript,true]let atmos_temperature = 0
let temperature = 0
input.onPinPressed(TouchPin.P0, () => {
    atmos_temperature = 250
    basic.showString("GAS")
})
input.onPinPressed(TouchPin.P2, () => {
    atmos_temperature = 0
    basic.showString("SOLID")
})
input.onPinPressed(TouchPin.P1, () => {
    atmos_temperature = 80
    basic.showString("LIQUID")
})
atmos_temperature = 100
temperature = 100[/mw_shl_code]

第5步:提高温度
BBC micro:bit|SCIENCE|物质的转换图5
[mw_shl_code=applescript,true]let atmos_temperature = 0
let temperature = 0
input.onGesture(Gesture.Shake, () => {
    temperature += 50
    basic.showIcon(IconNames.Triangle)
})
input.onPinPressed(TouchPin.P0, () => {
    atmos_temperature = 250
    basic.showString("GAS")
})
input.onPinPressed(TouchPin.P2, () => {
    atmos_temperature = 0
    basic.showString("SOLID")
})
input.onPinPressed(TouchPin.P1, () => {
    atmos_temperature = 80
    basic.showString("LIQUID")
})
atmos_temperature = 100
temperature = 100[/mw_shl_code]

第6步:显示温度变化
BBC micro:bit|SCIENCE|物质的转换图6

BBC micro:bit|SCIENCE|物质的转换图7
[mw_shl_code=applescript,true]let atmos_temperature = 0
let temperature = 0
input.onGesture(Gesture.Shake, () => {
    temperature += 50
    basic.showIcon(IconNames.Triangle)
})
basic.forever(() => {
    if (temperature < atmos_temperature) {
        temperature += 20
    } else {
        temperature += -20
    }
    if (temperature < 32) {
        basic.showIcon(IconNames.Square)
    } else if (temperature < 212) {
        basic.showIcon(IconNames.Umbrella)
    } else {
        basic.showIcon(IconNames.Chessboard)
    }
    basic.clearScreen()
    basic.pause(100)
})
input.onPinPressed(TouchPin.P0, () => {
    atmos_temperature = 250
    basic.showString("GAS")
})
input.onPinPressed(TouchPin.P2, () => {
    atmos_temperature = 0
    basic.showString("SOLID")
})
input.onPinPressed(TouchPin.P1, () => {
    atmos_temperature = 80
    basic.showString("LIQUID")
})
atmos_temperature = 100
temperature = 100[/mw_shl_code]


gada888  版主

发表于 2019-2-16 08:41:41

有趣
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail