hybridgroup.gobot/examples/firmata_wiichuck.go

34 lines
785 B
Go
Raw Normal View History

package main
import (
"fmt"
"github.com/hybridgroup/gobot"
2014-05-23 10:22:14 +08:00
"github.com/hybridgroup/gobot/platforms/firmata"
"github.com/hybridgroup/gobot/platforms/i2c"
)
func main() {
2014-05-23 10:22:14 +08:00
gbot := gobot.NewGobot()
firmataAdaptor := firmata.NewFirmataAdaptor("firmata", "/dev/ttyACM0")
wiichuck := i2c.NewWiichuckDriver(firmataAdaptor, "wiichuck")
work := func() {
gobot.On(wiichuck.Events["joystick"], func(data interface{}) {
fmt.Println("joystick")
})
gobot.On(wiichuck.Events["c_button"], func(data interface{}) {
fmt.Println("c")
})
gobot.On(wiichuck.Events["z_button"], func(data interface{}) {
fmt.Println("z")
})
}
2014-05-23 10:22:14 +08:00
gbot.Robots = append(gbot.Robots,
gobot.NewRobot("chuck", []gobot.Connection{firmataAdaptor}, []gobot.Device{wiichuck}, work))
2014-05-23 10:22:14 +08:00
gbot.Start()
}