hybridgroup.gobot/examples/firmata_wiichuck.go

41 lines
782 B
Go
Raw Normal View History

package main
import (
"fmt"
2014-07-11 08:21:21 +08:00
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/i2c"
"gobot.io/x/gobot/platforms/firmata"
)
func main() {
firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0")
wiichuck := i2c.NewWiichuckDriver(firmataAdaptor)
work := func() {
wiichuck.On(wiichuck.Event("joystick"), func(data interface{}) {
2014-06-08 11:38:45 +08:00
fmt.Println("joystick", data)
})
wiichuck.On(wiichuck.Event("c"), func(data interface{}) {
fmt.Println("c")
})
wiichuck.On(wiichuck.Event("z"), func(data interface{}) {
fmt.Println("z")
})
wiichuck.On(wiichuck.Event("error"), func(data interface{}) {
fmt.Println("Wiichuck error:", data)
})
}
2014-07-09 09:36:14 +08:00
robot := gobot.NewRobot("chuck",
[]gobot.Connection{firmataAdaptor},
[]gobot.Device{wiichuck},
work,
)
robot.Start()
}