From ba6e46da2f7acc580c8d2c93540115b79f388dfa Mon Sep 17 00:00:00 2001 From: Jonathan Resnick <3383923+resnickj@users.noreply.github.com> Date: Wed, 20 Mar 2024 17:37:21 -0400 Subject: [PATCH] Update pulseIn.adoc Add warning about measurements being affected by interrupts. --- Language/Functions/Advanced IO/pulseIn.adoc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Language/Functions/Advanced IO/pulseIn.adoc b/Language/Functions/Advanced IO/pulseIn.adoc index 5252f681..639bb6c1 100644 --- a/Language/Functions/Advanced IO/pulseIn.adoc +++ b/Language/Functions/Advanced IO/pulseIn.adoc @@ -74,6 +74,24 @@ void loop() { ---- [%hardbreaks] + +[float] +=== Notes and Warnings +Note that interrupts can affect the measured time reported by this function. When measuring relatively short pulses, you may need to temporarily disable interrupts (see link:../Interrupts/noInterrupts[noInterrupts()]) to obtain accurate and consistent results. For example, + +[source,arduino] +---- +void loop() { + noInterrupts(); + duration = pulseIn(pin, HIGH); + interrupts(); + + Serial.println(duration); +} +---- +[%hardbreaks] + + -- // HOW TO USE SECTION ENDS