Skip to content

Commit b600484

Browse files
committed
make readme example match simpletest
1 parent ac31193 commit b600484

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

README.rst

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,22 @@ See Also:
9898
Without a Context Manager
9999
-------------------------
100100

101-
In the example below, we create the `HCSR04` object directly, get the distance every 2 seconds, then
102-
de-initialize the device.
101+
In the example below, we create the `HCSR04` object directly, get the distance every 2 seconds.
103102

104103
.. code-block:: python
105104
105+
import time
106106
import board
107-
from adafruit_hcsr04 import HCSR04
108-
sonar = HCSR04(trigger_pin=board.D5, echo_pin=board.D6)
109-
try:
110-
while True:
111-
print(sonar.distance)
112-
sleep(2)
113-
except KeyboardInterrupt:
114-
pass
115-
sonar.deinit()
107+
import adafruit_hcsr04
108+
109+
sonar = adafruit_hcsr04.HCSR04(trigger_pin=board.D5, echo_pin=board.D6)
110+
111+
while True:
112+
try:
113+
print((sonar.distance,))
114+
except RuntimeError:
115+
print("Retrying!")
116+
time.sleep(2)
116117
117118
118119
With a Context Manager

0 commit comments

Comments
 (0)