forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
firmata_wiichuck.go
43 lines (33 loc) · 886 Bytes
/
firmata_wiichuck.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package main
import (
"fmt"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/platforms/firmata"
"github.com/hybridgroup/gobot/platforms/i2c"
)
func main() {
gbot := gobot.NewGobot()
firmataAdaptor := firmata.NewFirmataAdaptor("firmata", "/dev/ttyACM0")
wiichuck := i2c.NewWiichuckDriver(firmataAdaptor, "wiichuck")
work := func() {
gobot.On(wiichuck.Event("joystick"), func(data interface{}) {
fmt.Println("joystick", data)
})
gobot.On(wiichuck.Event("c"), func(data interface{}) {
fmt.Println("c")
})
gobot.On(wiichuck.Event("z"), func(data interface{}) {
fmt.Println("z")
})
gobot.On(wiichuck.Event("error"), func(data interface{}) {
fmt.Println("Wiichuck error:", data)
})
}
robot := gobot.NewRobot("chuck",
[]gobot.Connection{firmataAdaptor},
[]gobot.Device{wiichuck},
work,
)
gbot.AddRobot(robot)
gbot.Start()
}