hybridgroup.gobot/examples/firmata_wiichuck.go

57 lines
1.0 KiB
Go

//go:build example
// +build example
//
// Do not build by default.
/*
How to run
Pass serial port to use as the first param:
go run examples/firmata_wiichuck.go /dev/ttyACM0
*/
package main
import (
"fmt"
"os"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/drivers/i2c"
"gobot.io/x/gobot/v2/platforms/firmata"
)
func main() {
firmataAdaptor := firmata.NewAdaptor(os.Args[1])
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,
)
if err := robot.Start(); err != nil {
panic(err)
}
}