分页: 1 / 1

Gobot - Microbit 平台的 Golang Framework

发表于 : 2019年 11月 12日 21:40
shaoziyang
原帖作者:imhori来源: Microbit with Gobot

图片
还在起步阶段:

The Gobot platform for the Microbit includes several different drivers, each one corresponding to a different capability:
  • AccelerometerDriver
  • ButtonDriver
  • IOPinDriver
  • LEDDriver
  • MagnetometerDriver
  • TemperatureDriver

Re: Gobot - Microbit 平台的 Golang Framework

发表于 : 2019年 11月 12日 21:41
shaoziyang
LEDDriver

代码: 全选

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()
}
 

Re: Gobot - Microbit 平台的 Golang Framework

发表于 : 2019年 11月 12日 21:41
shaoziyang
GPIO and AIO Drivers

代码: 全选

package main

import (
        "os"

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

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

        ubit := microbit.NewIOPinDriver(bleAdaptor)
        button := gpio.NewButtonDriver(ubit, "0")
        led := gpio.NewLedDriver(ubit, "1")

        work := func() {
                button.On(gpio.ButtonPush, func(data interface{}) {
                        led.On()
                })
                button.On(gpio.ButtonRelease, func(data interface{}) {
                        led.Off()
                })
        }

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

        robot.Start()
}