2013-12-13 05:51:22 +05:30
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
|
2014-02-27 04:24:53 +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-02-27 04:24:53 +05:30
|
|
|
gpio, err := embd.NewGPIO()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer gpio.Close()
|
|
|
|
|
|
|
|
echoPin, err := gpio.DigitalPin(10)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
triggerPin, err := gpio.DigitalPin(9)
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|