gobot.io/x/gobot/v2@v2.1.0/examples/firmata_curie_imu_tap_detect.go (about) 1 //go:build example 2 // +build example 3 4 // 5 // Do not build by default. 6 7 /* 8 How to run 9 Pass serial port to use as the first param: 10 11 go run examples/firmata_curie_imu_tap_detect.go /dev/ttyACM0 12 */ 13 14 package main 15 16 import ( 17 "log" 18 "os" 19 "time" 20 21 "gobot.io/x/gobot/v2" 22 "gobot.io/x/gobot/v2/drivers/gpio" 23 "gobot.io/x/gobot/v2/platforms/firmata" 24 "gobot.io/x/gobot/v2/platforms/intel-iot/curie" 25 ) 26 27 func main() { 28 firmataAdaptor := firmata.NewAdaptor(os.Args[1]) 29 led := gpio.NewLedDriver(firmataAdaptor, "13") 30 imu := curie.NewIMUDriver(firmataAdaptor) 31 32 work := func() { 33 imu.On("Tap", func(data interface{}) { 34 log.Println("Tap", data) 35 }) 36 37 gobot.Every(1*time.Second, func() { 38 led.Toggle() 39 }) 40 41 imu.EnableTapDetection(true) 42 } 43 44 robot := gobot.NewRobot("curieBot", 45 []gobot.Connection{firmataAdaptor}, 46 []gobot.Device{imu, led}, 47 work, 48 ) 49 50 robot.Start() 51 }