Skip to content

Ultrasonic Distance Sensor: Try a different strategy with pulseIn()#1

Open
gohai wants to merge 1 commit intomainfrom
pulseIn-timeout
Open

Ultrasonic Distance Sensor: Try a different strategy with pulseIn()#1
gohai wants to merge 1 commit intomainfrom
pulseIn-timeout

Conversation

@gohai
Copy link
Collaborator

@gohai gohai commented Jan 28, 2024

@XCF-KHX How would you think about something like this?

This sets a timeout for pulseIn to 11ms (believe that's 200cm?), so we should never take more time than that out of the loop(). If we miss five pulses in a row, we assume the distance is out-of-range. Otherwise, we believe in our most recent reading.

This could be made into a function that returns an int, with a static variable for missed pulses.

@XCF-KHX How would you think about something like this?

This sets a timeout for pulseIn to 11ms (believe that's 200cm?), so we should never take more time than that out of the loop(). If we miss five pulses in a row, we assume the distance is out-of-range. Otherwise, we believe in our most recent reading.

This could be made into a function that returns an int, with a static variable for missed pulses.
@gohai gohai requested a review from XCF-KHX January 28, 2024 06:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant