lunes, 18 de noviembre de 2024

Arduino - Digital Pins With Interrupts - Input Capture - Output Compare

Arduino - Digital Pins With Interrupts - Input Capture - Output Compare

Example Code

const byte ledPin = 13;
const byte interruptPin = 2;
volatile byte state = LOW;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(interruptPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin), blink, CHANGE);
}

void loop() {
  digitalWrite(ledPin, state);
}

void blink() {
  state = !state;
}

attachInterrupt()

[External Interrupts]

Description

Digital Pins With Interrupts

The first parameter to attachInterrupt is an interrupt number. Normally you should use digitalPinToInterrupt(pin) to translate the actual digital pin to the specific interrupt number. For example, if you connect to pin 3, use digitalPinToInterrupt(3) as the first parameter to attachInterrupt.

BoardDigital Pins Usable For Interrupts

Uno, Nano, Mini, other 328-based

2, 3

Mega, Mega2560, MegaADK

2, 3, 18, 19, 20, 21

Micro, Leonardo, other 32u4-based

0, 1, 2, 3, 7

Zero

all digital pins, except 4

MKR1000 Rev.1

0, 1, 4, 5, 6, 7, 8, 9, A1, A2

Due

all digital pins

101

all digital pins (Only pins 2, 5, 7, 8, 10, 11, 12, 13 work with CHANGE)

No hay comentarios:

Publicar un comentario