Skip to content
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

Update attachInterrupt notes about mechanical switch chatter #576

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
4 changes: 3 additions & 1 deletion Language/Functions/External Interrupts/attachInterrupt.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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() {
Expand Down