用 Go 语言 (GOBOT) 控制 microbit

micro:bit编程、教学、展示
STEM
回复
头像
shaoziyang
帖子: 3917
注册时间: 2019年 10月 21日 13:48

用 Go 语言 (GOBOT) 控制 microbit

#1

帖子 shaoziyang »

来自:https://gobot.io/documentation/platforms/microbit/

图片
首先要安装

  go get -d -u gobot.io/x/gobot/...

然后可以通过程序控制

代码: 全选

package main

import (
        "os"
        "time"

        "gobot.io/x/gobot"
        "gobot.io/x/gobot/platforms/ble"
        "gobot.io/x/gobot/platforms/microbit"
)

func main() {
        bleAdaptor := ble.NewClientAdaptor(os.Args[1])
        ubit := microbit.NewLEDDriver(bleAdaptor)

        work := func() {
                ubit.Blank()
                gobot.After(1*time.Second, func() {
                        ubit.WriteText("Hello")
                })
                gobot.After(7*time.Second, func() {
                        ubit.Smile()
                })
        }

        robot := gobot.NewRobot("blinkBot",
                []gobot.Connection{bleAdaptor},
                []gobot.Device{ubit},
                work,
        )

        robot.Start()
}
 

回复

  • 随机主题
    回复总数
    阅读次数
    最新文章