-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
firmata_curie_imu_step_counter.go
51 lines (39 loc) · 875 Bytes
/
firmata_curie_imu_step_counter.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
//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_curie_imu_step_counter.go /dev/ttyACM0
*/
package main
import (
"log"
"os"
"time"
"gobot.io/x/gobot/v2"
"gobot.io/x/gobot/v2/drivers/gpio"
"gobot.io/x/gobot/v2/platforms/firmata"
"gobot.io/x/gobot/v2/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("Steps", func(data interface{}) {
log.Println("Steps", data)
})
gobot.Every(1*time.Second, func() {
led.Toggle()
})
imu.EnableStepCounter(true)
}
robot := gobot.NewRobot("curieBot",
[]gobot.Connection{firmataAdaptor},
[]gobot.Device{imu, led},
work,
)
robot.Start()
}