mirror of
https://github.com/hybridgroup/gobot.git
synced 2025-05-11 19:29:20 +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
|
package gpio
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hybridgroup/gobot"
|
"github.com/hybridgroup/gobot"
|
||||||
@ -63,11 +62,12 @@ func (p *PIRMotionDriver) Start() (errs []error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
p.Publish(Error, err)
|
p.Publish(Error, err)
|
||||||
}
|
}
|
||||||
fmt.Println(newValue)
|
|
||||||
switch newValue {
|
switch newValue {
|
||||||
case 1:
|
case 1:
|
||||||
p.Active = true
|
if !p.Active {
|
||||||
p.Publish(MotionDetected, newValue)
|
p.Active = true
|
||||||
|
p.Publish(MotionDetected, newValue)
|
||||||
|
}
|
||||||
case 0:
|
case 0:
|
||||||
if p.Active {
|
if p.Active {
|
||||||
p.Active = false
|
p.Active = false
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/hybridgroup/gobot"
|
"github.com/hybridgroup/gobot"
|
||||||
"github.com/hybridgroup/gobot/drivers/gpio"
|
"github.com/hybridgroup/gobot/drivers/gpio"
|
||||||
"github.com/hybridgroup/gobot/platforms/firmata"
|
"github.com/hybridgroup/gobot/platforms/firmata"
|
||||||
@ -14,9 +16,11 @@ func main() {
|
|||||||
|
|
||||||
work := func() {
|
work := func() {
|
||||||
sensor.On(gpio.MotionDetected, func(data interface{}) {
|
sensor.On(gpio.MotionDetected, func(data interface{}) {
|
||||||
|
fmt.Println(gpio.MotionDetected)
|
||||||
led.On()
|
led.On()
|
||||||
})
|
})
|
||||||
sensor.On(gpio.MotionStopped, func(data interface{}) {
|
sensor.On(gpio.MotionStopped, func(data interface{}) {
|
||||||
|
fmt.Println(gpio.MotionStopped)
|
||||||
led.Off()
|
led.Off()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user