1
0
mirror of https://github.com/kidoman/embd synced 2024-12-22 21:00:05 +01:00
embd/samples/us020.go
Karan Misra 9ab49745bc - use glog instead of Debug flag
- use glog instead of log
- make code conform to the Go code guidelines
2014-03-31 18:46:04 +05:30

41 lines
596 B
Go

// +build ignore
package main
import (
"fmt"
"time"
"github.com/kidoman/embd"
"github.com/kidoman/embd/sensor/us020"
)
func main() {
if err := embd.InitGPIO(); err != nil {
panic(err)
}
defer embd.CloseGPIO()
echoPin, err := embd.NewDigitalPin(10)
if err != nil {
panic(err)
}
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 {
panic(err)
}
fmt.Printf("Distance is %v\n", distance)
time.Sleep(500 * time.Millisecond)
}
}