package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"gobot.io/x/gobot"
|
|
"gobot.io/x/gobot/drivers/gpio"
|
|
"gobot.io/x/gobot/platforms/raspi"
|
|
)
|
|
|
|
func main() {
|
|
r := raspi.NewAdaptor()
|
|
led1 := gpio.NewLedDriver(r, "29")
|
|
//led2 := gpio.NewLedDriver(r, "31")
|
|
//led3 := gpio.NewLedDriver(r, "33")
|
|
led4 := gpio.NewLedDriver(r, "35")
|
|
|
|
motion := gpio.NewPIRMotionDriver(r, "16")
|
|
|
|
work := func() {
|
|
motion.On(gpio.MotionDetected, func(data interface{}) {
|
|
fmt.Println(gpio.MotionDetected)
|
|
led1.On()
|
|
led4.On()
|
|
})
|
|
|
|
motion.On(gpio.MotionStopped, func(data interface{}) {
|
|
fmt.Println(gpio.MotionStopped)
|
|
led1.Off()
|
|
led4.Off()
|
|
})
|
|
}
|
|
|
|
robot := gobot.NewRobot("Nistkasten",
|
|
[]gobot.Connection{r},
|
|
[]gobot.Device{motion, led1, led4},
|
|
work,
|
|
)
|
|
|
|
robot.Start()
|
|
}
|