1
0
mirror of https://github.com/kidoman/embd synced 2024-11-14 05:28:54 +01:00
embd/samples/us020.go

41 lines
598 B
Go
Raw Normal View History

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