Skip to content

Update to the correct distance call #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 20, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ 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.
de-initialize the device. Note trig and echo should come from the `board` module - they aren't just integers.

::

from adafruit_hcsr04 import HCSR04
sonar = HCSR04(trig, echo)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing the out of date example in the readme!

Instead of making a note in the paragraph above can you update this line in the example code to show it's usage with the board pins. You can copy it form the example file in the repo if you want:
https://github.com/adafruit/Adafruit_CircuitPython_HCSR04/blob/master/examples/hcsr04_simpletest.py

You can add import board at the top and then change the sonar constructor like this:

sonar = HCSR04(trigger_pin=board.D5, echo_pin=board.D6)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I've committed this change.

try:
while True:
print(sonar.dist_cm())
print(sonar.distance)
sleep(2)
except KeyboardInterrupt:
pass
Expand All @@ -127,7 +127,7 @@ us.
with HCSR04(trig, echo) as sonar:
try:
while True:
print(sonar.dist_cm())
print(sonar.distance)
sleep(2)
except KeyboardInterrupt:
pass
Expand Down