Skip to content

How to use pulseIn in arduino #309

Answered by Rahix
zxlzy asked this question in Q&A
Discussion options

You must be logged in to vote

Right now, there doesn't exist any plug-and-play replacement - you'll have to build your own. Depending on what you need, you can repurpose some of the code from the HC-SR04 example. This part in particular uses a timer to measure the response time of he sensor:

// the timer is reinitialized with value 0.
timer1.tcnt1.write(|w| unsafe { w.bits(0) });
// the trigger must be set to high under 10 µs as per the HC-SR04 datasheet
trig.set_high();
arduino_hal::delay_us(10);
trig.set_low();
while echo.is_low() {
// exiting the loop if the timer has reached 200 ms.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Rahix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #228 on September 02, 2022 10:27.