hybridgroup.gobot/examples/ble_battery.go

34 lines
552 B
Go
Raw Normal View History

package main
import (
"fmt"
"time"
"os"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/ble"
)
func main() {
gbot := gobot.NewGobot()
bleAdaptor := ble.NewBLEAdaptor("ble", os.Args[1])
battery := ble.NewBLEBatteryDriver(bleAdaptor, "battery")
work := func() {
gobot.Every(5*time.Second, func() {
fmt.Println("Battery level:", battery.GetBatteryLevel())
})
}
robot := gobot.NewRobot("bleBot",
[]gobot.Connection{bleAdaptor},
[]gobot.Device{battery},
work,
)
gbot.AddRobot(robot)
gbot.Start()
}