1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-27 13:48:56 +08:00
hybridgroup.gobot/examples/firmata_hmc6352.go

35 lines
641 B
Go
Raw Normal View History

package main
import (
"fmt"
2014-07-10 17:21:21 -07:00
"time"
"github.com/hybridgroup/gobot"
2014-05-22 19:22:14 -07:00
"github.com/hybridgroup/gobot/platforms/firmata"
"github.com/hybridgroup/gobot/platforms/i2c"
)
func main() {
2014-05-22 19:22:14 -07:00
gbot := gobot.NewGobot()
2014-07-08 18:36:14 -07:00
firmataAdaptor := firmata.NewFirmataAdaptor("firmata", "/dev/ttyACM0")
2014-05-22 19:22:14 -07:00
hmc6352 := i2c.NewHMC6352Driver(firmataAdaptor, "hmc6352")
work := func() {
2014-06-06 18:58:04 -07:00
gobot.Every(100*time.Millisecond, func() {
heading, _ := hmc6352.Heading()
fmt.Println("Heading", heading)
})
}
2014-07-08 18:36:14 -07:00
robot := gobot.NewRobot("hmc6352Bot",
[]gobot.Connection{firmataAdaptor},
[]gobot.Device{hmc6352},
work,
)
gbot.AddRobot(robot)
2014-05-22 19:22:14 -07:00
gbot.Start()
}