2017-03-13 23:01:39 +08:00
|
|
|
// +build example
|
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
2016-10-22 21:17:49 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-10-31 05:07:01 +08:00
|
|
|
"fmt"
|
|
|
|
|
2016-12-08 20:24:03 +08:00
|
|
|
"gobot.io/x/gobot"
|
|
|
|
"gobot.io/x/gobot/drivers/gpio"
|
|
|
|
"gobot.io/x/gobot/platforms/firmata"
|
2016-10-22 21:17:49 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0")
|
|
|
|
|
|
|
|
sensor := gpio.NewPIRMotionDriver(firmataAdaptor, "5")
|
|
|
|
led := gpio.NewLedDriver(firmataAdaptor, "13")
|
|
|
|
|
|
|
|
work := func() {
|
|
|
|
sensor.On(gpio.MotionDetected, func(data interface{}) {
|
2016-10-31 05:07:01 +08:00
|
|
|
fmt.Println(gpio.MotionDetected)
|
2016-10-22 21:17:49 +08:00
|
|
|
led.On()
|
|
|
|
})
|
|
|
|
sensor.On(gpio.MotionStopped, func(data interface{}) {
|
2016-10-31 05:07:01 +08:00
|
|
|
fmt.Println(gpio.MotionStopped)
|
2016-10-22 21:17:49 +08:00
|
|
|
led.Off()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("motionBot",
|
|
|
|
[]gobot.Connection{firmataAdaptor},
|
|
|
|
[]gobot.Device{sensor, led},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
|
|
|
robot.Start()
|
|
|
|
}
|