分页: 1 / 1

在microbit上使用触摸按键

发表于 : 2019年 11月 12日 21:38
shaoziyang
microbit的P0-P2支持触摸功能,可以当作触摸键。下面程序演示的用法,它的功能是按下P0,计数器清零;按下P1,计数器加1;按下P2,计数器加2。

代码: 全选

input.onPinPressed(TouchPin.P1, function () {
    counter += 1
})
input.onPinPressed(TouchPin.P2, function () {
    counter += 2
})
input.onPinPressed(TouchPin.P0, function () {
    counter = 0
})
let counter = 0
counter = 0
basic.forever(function () {
    basic.showNumber(counter)
})
在线编辑