From 2e2895347225703f47277e6188d5f8e606794e0e Mon Sep 17 00:00:00 2001 From: PaulStoffregen Date: Wed, 27 Mar 2019 17:01:06 -0700 Subject: [PATCH] Update attachInterrupt notes about mechanical switch chatter --- Language/Functions/External Interrupts/attachInterrupt.adoc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Language/Functions/External Interrupts/attachInterrupt.adoc b/Language/Functions/External Interrupts/attachInterrupt.adoc index a0b20191d..3688cd83b 100644 --- a/Language/Functions/External Interrupts/attachInterrupt.adoc +++ b/Language/Functions/External Interrupts/attachInterrupt.adoc @@ -37,6 +37,8 @@ The first parameter to `attachInterrupt()` is an interrupt number. Normally you *Note* + Inside the attached function, `delay()` won't work and the value returned by `millis()` will not increment. Serial data received while in the function may be lost. You should declare as `volatile` any variables that you modify within the attached function. See the section on ISRs below for more information. + +Pushbuttons, switches, and relays have mechanical chatter which can cause many rapid signal changes. The https://github.com/thomasfredericks/Bounce2[Bounce2 library] is often a better choice than `attachInterrupt()` to reliably detect changes from mechanical switches. [%hardbreaks] [float] @@ -97,7 +99,7 @@ Nothing [source,arduino] ---- const byte ledPin = 13; -const byte interruptPin = 2; +const byte interruptPin = 2; // Use a "clean" digital signal. See notes about mechanical switch chatter. volatile byte state = LOW; void setup() {