A little curiosity. A whole lot of making.Robotics, CNC & connected ideas
robodatech.
Arduino sample library

Interrupt Counter 30

Count encoder ticks and fast events with external interrupts.

Open in compiler →
/*
  Roboda verified Arduino sample 0737
  Feature: Interrupt Counter
  Generated for online build, classroom practice, and hardware upload testing.
*/

volatile unsigned long ticks = 0;

void onPulse() {
  ticks++;
}

void setup() {
  Serial.begin(9600);
  pinMode(2, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(2), onPulse, FALLING);
}

void loop() {
  noInterrupts();
  unsigned long copy = ticks;
  interrupts();
  Serial.println(copy);
  delay(255);
}

How it works

Practice this Arduino feature with a verified Roboda sketch.

  1. Read the constants at the top of the sketch.
  2. Wire the pins exactly as listed in the pin map.
  3. Upload or compile once before changing values.
  4. Change one value at a time and watch Serial Monitor or the output device.

Connections

PinConnect toNote
D2Encoder channel, pulse sensor, or button to GNDUse an interrupt-capable pin on your selected board.

Good ideas start here.

Robotics lessons, build notes and useful updates. Subscribe by entering your email.