1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-05-09 19:29:27 +08:00

gpio: display events in PIR detect example

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram 2016-10-30 22:07:01 +01:00
parent d82e893e6f
commit e01baa7b75
2 changed files with 8 additions and 4 deletions

View File

@ -1,7 +1,6 @@
package gpio
import (
"fmt"
"time"
"github.com/hybridgroup/gobot"
@ -63,11 +62,12 @@ func (p *PIRMotionDriver) Start() (errs []error) {
if err != nil {
p.Publish(Error, err)
}
fmt.Println(newValue)
switch newValue {
case 1:
p.Active = true
p.Publish(MotionDetected, newValue)
if !p.Active {
p.Active = true
p.Publish(MotionDetected, newValue)
}
case 0:
if p.Active {
p.Active = false

View File

@ -1,6 +1,8 @@
package main
import (
"fmt"
"github.com/hybridgroup/gobot"
"github.com/hybridgroup/gobot/drivers/gpio"
"github.com/hybridgroup/gobot/platforms/firmata"
@ -14,9 +16,11 @@ func main() {
work := func() {
sensor.On(gpio.MotionDetected, func(data interface{}) {
fmt.Println(gpio.MotionDetected)
led.On()
})
sensor.On(gpio.MotionStopped, func(data interface{}) {
fmt.Println(gpio.MotionStopped)
led.Off()
})
}