1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-24 13:48:49 +08:00
hybridgroup.gobot/examples/microbit_blink.go
Thomas Kohler 865e724af0
Build(v2): revert move to v2 subfolder (#932)
* revert move to v2 subfolder
* fix CI and adjust CHANGELOG
2023-05-29 19:23:28 +02:00

62 lines
1.2 KiB
Go

//go:build example
// +build example
//
// Do not build by default.
/*
How to setup
You must be using a BBC Microbit microcontroller that has
been flashed with the firmware from @sandeepmistry
More info:
https://gobot.io/documentation/platforms/microbit/#how-to-install
This example requires that you wire an external LED to
pin number 0 on the Microbit, as this example is intended
to demonstrate the Microbit IOPinDriver.
You then run the Go program on your computer and communicate
wirelessly with the Microbit.
How to run
Pass the Bluetooth name or address as first param:
go run examples/microbit_blink.go "BBC micro:bit [yowza]"
NOTE: sudo is required to use BLE in Linux
*/
package main
import (
"os"
"time"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/drivers/gpio"
"gobot.io/x/gobot/v2/platforms/ble"
"gobot.io/x/gobot/v2/platforms/microbit"
)
func main() {
bleAdaptor := ble.NewClientAdaptor(os.Args[1])
ubit := microbit.NewIOPinDriver(bleAdaptor)
led := gpio.NewLedDriver(ubit, "0")
work := func() {
gobot.Every(1*time.Second, func() {
led.Toggle()
})
}
robot := gobot.NewRobot("bot",
[]gobot.Connection{bleAdaptor},
[]gobot.Device{ubit, led},
work,
)
robot.Start()
}