2014-03-02 12:36:34 +05:30
|
|
|
// +build ignore
|
|
|
|
|
2013-12-13 05:51:22 +05:30
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
|
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/us020"
|
2013-12-13 05:51:22 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2014-03-03 00:51:23 +05:30
|
|
|
if err := embd.InitGPIO(); err != nil {
|
2014-02-27 04:24:53 +05:30
|
|
|
panic(err)
|
|
|
|
}
|
2014-03-03 00:51:23 +05:30
|
|
|
defer embd.CloseGPIO()
|
2014-02-27 04:24:53 +05:30
|
|
|
|
2014-03-03 00:51:23 +05:30
|
|
|
echoPin, err := embd.NewDigitalPin(10)
|
2014-02-27 04:24:53 +05:30
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2014-03-03 00:51:23 +05:30
|
|
|
triggerPin, err := embd.NewDigitalPin(9)
|
2014-02-27 04:24:53 +05:30
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2014-02-08 02:21:01 +05:30
|
|
|
|
2014-02-27 04:24:53 +05:30
|
|
|
rf := us020.New(echoPin, triggerPin, nil)
|
2014-01-09 03:39:06 +05:30
|
|
|
defer rf.Close()
|
2013-12-13 05:51:22 +05:30
|
|
|
|
|
|
|
for {
|
2014-01-09 03:39:06 +05:30
|
|
|
distance, err := rf.Distance()
|
2013-12-13 05:51:22 +05:30
|
|
|
if err != nil {
|
|
|
|
log.Panic(err)
|
|
|
|
}
|
|
|
|
log.Printf("Distance is %v", distance)
|
|
|
|
|
|
|
|
time.Sleep(500 * time.Millisecond)
|
|
|
|
}
|
|
|
|
}
|