diff --git a/samples/us020.go b/samples/us020.go index 96c88f2..363cca3 100644 --- a/samples/us020.go +++ b/samples/us020.go @@ -9,6 +9,7 @@ import ( func main() { rangeFinder := us020.New(10, 9) + defer rangeFinder.Close() for { distance, err := rangeFinder.Distance() diff --git a/sensor/us020/us020.go b/sensor/us020/us020.go index c3497fa..d7be4d3 100644 --- a/sensor/us020/us020.go +++ b/sensor/us020/us020.go @@ -18,6 +18,8 @@ const ( type US020 interface { // Distance computes the distance of the bot from the closest obstruction. Distance() (float64, error) + + Close() } type us020 struct { @@ -117,3 +119,8 @@ func (d *us020) Distance() (distance float64, err error) { return } + +func (d *us020) Close() { + d.echoPin.Output() + rpio.Close() +}