diff --git a/README.rst b/README.rst index 56d0263..974de9d 100644 --- a/README.rst +++ b/README.rst @@ -90,7 +90,7 @@ See Also: `_ (the guide linked was written for the pyboard, but it still works), then input the following: - :: + .. code-block:: python import board dir(board) @@ -98,20 +98,22 @@ See Also: Without a Context Manager ------------------------- -In the example below, we create the `HCSR04` object directly, get the distance every 2 seconds, then -de-initialize the device. +In the example below, we create the `HCSR04` object directly, get the distance every 2 seconds. -:: +.. code-block:: python - from adafruit_hcsr04 import HCSR04 - sonar = HCSR04(trig, echo) - try: - while True: - print(sonar.dist_cm()) - sleep(2) - except KeyboardInterrupt: - pass - sonar.deinit() + import time + import board + import adafruit_hcsr04 + + sonar = adafruit_hcsr04.HCSR04(trigger_pin=board.D5, echo_pin=board.D6) + + while True: + try: + print((sonar.distance,)) + except RuntimeError: + print("Retrying!") + time.sleep(2) With a Context Manager @@ -121,13 +123,14 @@ In the example below, we use a context manager (the `with