1
0
mirror of https://github.com/kidoman/embd synced 2024-11-13 21:18:55 +01:00
embd/samples/watersensor.go

46 lines
636 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 (
"flag"
2013-12-23 12:09:52 +01:00
"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"
_ "github.com/kidoman/embd/host/all"
2013-12-23 12:09:52 +01:00
)
func main() {
flag.Parse()
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)
}
}