forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ble_firmata_curie_imu.go
63 lines (49 loc) · 1.14 KB
/
ble_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
// +build example
//
// Do not build by default.
/*
How to run
Pass the BLE address or BLE name as first param:
go run examples/ble_firmata_curie_imu.go FIRMATA
NOTE: sudo is required to use BLE in Linux
*/
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.NewBLEAdaptor(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)
})
gobot.Every(1*time.Second, func() {
led.Toggle()
})
gobot.Every(100*time.Millisecond, func() {
imu.ReadAccelerometer()
imu.ReadGyroscope()
imu.ReadTemperature()
})
}
robot := gobot.NewRobot("bot",
[]gobot.Connection{firmataAdaptor},
[]gobot.Device{led, imu},
work,
)
robot.Start()
}