2013-12-13 01:21:22 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
|
2014-02-10 00:35:41 +01:00
|
|
|
"github.com/kidoman/embd/sensor/us020"
|
2014-02-07 21:51:01 +01:00
|
|
|
"github.com/stianeikeland/go-rpio"
|
2013-12-13 01:21:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2014-02-07 21:51:01 +01:00
|
|
|
rpio.Open()
|
|
|
|
defer rpio.Close()
|
|
|
|
|
2014-01-08 23:09:06 +01:00
|
|
|
rf := us020.New(10, 9, nil)
|
|
|
|
defer rf.Close()
|
2013-12-13 01:21:22 +01:00
|
|
|
|
|
|
|
for {
|
2014-01-08 23:09:06 +01:00
|
|
|
distance, err := rf.Distance()
|
2013-12-13 01:21:22 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Panic(err)
|
|
|
|
}
|
|
|
|
log.Printf("Distance is %v", distance)
|
|
|
|
|
|
|
|
time.Sleep(500 * time.Millisecond)
|
|
|
|
}
|
|
|
|
}
|