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

46 lines
636 B
Go
Raw Normal View History

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