hybridgroup.gobot/examples/firmata_wiichuck.go

41 lines
782 B
Go

package main
import (
"fmt"
"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{}) {
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)
})
}
robot := gobot.NewRobot("chuck",
[]gobot.Connection{firmataAdaptor},
[]gobot.Device{wiichuck},
work,
)
robot.Start()
}