hybridgroup.gobot/examples/ble_battery.go

30 lines
502 B
Go
Raw Normal View History

package main
import (
"fmt"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/ble"
)
func main() {
gbot := gobot.NewGobot()
2016-03-03 14:00:05 +08:00
bleAdaptor := ble.NewBLEAdaptor("ble", "D0:39:72:C9:9E:5A")
battery := ble.NewBLEBatteryDriver(bleAdaptor, "battery")
work := func() {
2016-03-03 14:00:05 +08:00
fmt.Println("Battery level:", battery.GetBatteryLevel())
}
robot := gobot.NewRobot("bleBot",
[]gobot.Connection{bleAdaptor},
[]gobot.Device{battery},
work,
)
gbot.AddRobot(robot)
gbot.Start()
}