1
0
mirror of https://github.com/kidoman/embd synced 2024-10-31 23:38:44 +01:00
embd/samples/watersensor.go

41 lines
574 B
Go
Raw Normal View History

2014-03-02 08:06:34 +01:00
// +build ignore
2013-12-23 12:09:52 +01:00
package main
import (
"time"
2014-03-02 07:51:29 +01:00
"github.com/golang/glog"
2014-03-02 20:21:23 +01:00
"github.com/kidoman/embd"
2014-02-10 00:35:41 +01:00
"github.com/kidoman/embd/sensor/watersensor"
2013-12-23 12:09:52 +01:00
)
func main() {
2014-03-02 20:21:23 +01:00
if err := embd.InitGPIO(); err != nil {
2014-03-02 07:51:29 +01:00
panic(err)
}
2014-03-02 20:21:23 +01:00
defer embd.CloseGPIO()
2014-03-02 07:51:29 +01:00
2014-03-02 20:21:23 +01:00
pin, err := embd.NewDigitalPin(7)
2014-03-02 07:51:29 +01:00
if err != nil {
panic(err)
}
defer pin.Close()
fluidSensor := watersensor.New(pin)
2013-12-23 12:09:52 +01:00
for {
2014-03-02 07:51:29 +01:00
wet, err := fluidSensor.IsWet()
2013-12-23 12:09:52 +01:00
if err != nil {
2014-03-02 07:51:29 +01:00
panic(err)
2013-12-23 12:09:52 +01:00
}
2014-03-02 07:51:29 +01:00
if wet {
glog.Info("bot is dry")
2014-02-10 00:35:41 +01:00
} else {
2014-03-02 07:51:29 +01:00
glog.Info("bot is Wet")
2014-02-10 00:35:41 +01:00
}
2014-03-02 07:51:29 +01:00
2013-12-23 12:09:52 +01:00
time.Sleep(500 * time.Millisecond)
}
}