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:
parent
d82e893e6f
commit
e01baa7b75
@ -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
|
||||
|
@ -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()
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user