PaulStoffregen / Encoder

Quadrature Encoder Library for Arduino
http://www.pjrc.com/teensy/td_libs_Encoder.html
540 stars 239 forks source link

Attaching interrupt to another pin while using ENCODER_OPTIMIZE_INTERRUPTS #91

Open OsziBatyam opened 1 year ago

OsziBatyam commented 1 year ago

Description

I'm trying to use ENCODER_OPTIMIZE_INTERRUPTS and trying to attach an interrupt on another pin for something else. With the Arduino UNO I get the error message below and ESP 32 it compiles, but I only get garbage out. I do not get this use with the other two modes (use/ don't use Interrupts)

Steps To Reproduce Problem

  1. define ENCODER_OPTIMIZE_INTERRUPTS
  2. attach Interrupt to another pin

Hardware & Software

Board: UNO and ESP 32 Shields / modules used: none Arduino IDE version: 2.0.4 Version info & package name (from Tools > Boards > Board Manager) Operating system & version: Windows 11

Arduino Sketch


#include <Arduino.h>
#define ENCODER_OPTIMIZE_INTERRUPTS
#include <Encoder.h>

#define PIN_A 2
#define PIN_B 4
#define PIN_Z 3

Encoder encoder(PIN_A, PIN_B);

void isrZ() {}

void setup() {
  // put your setup code here, to run once:

  pinMode(PIN_Z, INPUT_PULLUP);

  // Attach the interrupt service routine to the Z channel
  attachInterrupt(digitalPinToInterrupt(PIN_Z), isrZ, RISING);

}

void loop() {
  // put your main code here, to run repeatedly:

}

Errors or Incorrect Output

WInterrupts.c.o (symbol from plugin): In function attachInterrupt': (.text+0x0): multiple definition ofvector_1' C:\Users\olive\AppData\Local\Temp\arduino\sketches\A8C24F6FC9A37B155D5799EA60E00EE0\sketch\sketch_apr12a.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here WInterrupts.c.o (symbol from plugin): In function attachInterrupt': (.text+0x0): multiple definition ofvector_2' C:\Users\olive\AppData\Local\Temp\arduino\sketches\A8C24F6FC9A37B155D5799EA60E00EE0\sketch\sketch_apr12a.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here collect2.exe: error: ld returned 1 exit status

exit status 1

Compilation error: exit status 1