forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
firmata_curie_imu.go
66 lines (52 loc) · 1.19 KB
/
firmata_curie_imu.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// +build example
//
// Do not build by default.
/*
How to run
Pass serial port to use as the first param:
go run examples/firmata_curie_imu.go /dev/ttyACM0
*/
package main
import (
"log"
"os"
"time"
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/platforms/firmata"
"gobot.io/x/gobot/platforms/intel-iot/curie"
)
func main() {
firmataAdaptor := firmata.NewAdaptor(os.Args[1])
led := gpio.NewLedDriver(firmataAdaptor, "13")
imu := curie.NewIMUDriver(firmataAdaptor)
work := func() {
imu.On("Accelerometer", func(data interface{}) {
log.Println("Accelerometer", data)
})
imu.On("Gyroscope", func(data interface{}) {
log.Println("Gyroscope", data)
})
imu.On("Temperature", func(data interface{}) {
log.Println("Temperature", data)
})
imu.On("Motion", func(data interface{}) {
log.Println("Motion", data)
})
gobot.Every(1*time.Second, func() {
led.Toggle()
})
gobot.Every(100*time.Millisecond, func() {
imu.ReadAccelerometer()
imu.ReadGyroscope()
imu.ReadTemperature()
imu.ReadMotion()
})
}
robot := gobot.NewRobot("curieBot",
[]gobot.Connection{firmataAdaptor},
[]gobot.Device{imu, led},
work,
)
robot.Start()
}