mirror of
https://github.com/hybridgroup/gobot.git
synced 2025-05-01 13:48:57 +08:00
33 lines
589 B
Go
33 lines
589 B
Go
![]() |
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
|
"github.com/hybridgroup/gobot"
|
||
|
"github.com/hybridgroup/gobot/platforms/gpio"
|
||
|
"github.com/hybridgroup/gobot/platforms/intel-iot/edison"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
gbot := gobot.NewGobot()
|
||
|
|
||
|
board := edison.NewEdisonAdaptor("edison")
|
||
|
sensor := gpio.NewGrovePiezoVibrationSensorDriver(board, "sensor", "0")
|
||
|
|
||
|
work := func() {
|
||
|
gobot.On(sensor.Event(gpio.Vibration), func(data interface{}) {
|
||
|
fmt.Println("got one!")
|
||
|
})
|
||
|
}
|
||
|
|
||
|
robot := gobot.NewRobot("bot",
|
||
|
[]gobot.Connection{board},
|
||
|
[]gobot.Device{sensor},
|
||
|
work,
|
||
|
)
|
||
|
|
||
|
gbot.AddRobot(robot)
|
||
|
|
||
|
gbot.Start()
|
||
|
}
|