GreyGnome / EnableInterrupt

New Arduino interrupt library, designed for Arduino Uno/Mega 2560/Leonardo/Due
329 stars 73 forks source link

Compile error with external interrupts #53

Closed jimbowley closed 5 years ago

jimbowley commented 5 years ago

Thanks for this library,

Should I be able to use both this and external interrupts together?

just including this library with my code causes compile error. I'm using a ProMicro (Leonardo) and IDE 1.8.1

include

include

include

//#include

define pinA1 1 //Roller A

define pinZ1 8 //Spinner

long cntX=0; //counter for mouse X-axis long lastcntX=0; float realX=0; float incX= 0.5; // This gives approx correct speed on missile command default sensitivity 20 float incZ= 0.1; // high resolution spinner needs low value here.

void setup() {

// pinMode(pinZ1, INPUT_PULLUP); // enableInterrupt(pinZ1,doZCount, CHANGE);

pinMode(pinA1, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(pinA1),doACountX,CHANGE);

Mouse.begin(); Keyboard.begin(); }

void loop() { //send mouse update to usb cntX = realX; if(cntX!=lastcntX ){ Mouse.move((cntX-lastcntX),0); lastcntX=cntX; } }

void doZCount() { // spinner is moving realX = realX +incZ; }

void doACountX() { // ball is moving realX = realX +incX; }

Mihai-B commented 5 years ago

I am not able to run this with external interrupts as well. With the deprecated library I was able to do so. I am now wondering if this is a bug?

happysupply commented 5 years ago

Same problem here. Tried compiling for Uno with both external and PinChange interrupts, through functions attachInterrupt() and enableInterrupt(). This didn't work.

When I replaced the attachInterrupts for enableInterrupts, the code did compile.

GreyGnome commented 5 years ago

I don't recall if this library will work with attachInterrupt(). But you don't need attachInterrupt(); enableInterrupt() will utilize the proper interrupt type on pins that support External Interrupts.

See https://github.com/GreyGnome/EnableInterrupt/wiki/Usage#Why_the_Interrupt_Designator_is_Not_a_Big_Deal

On Fri, Oct 19, 2018 at 5:39 PM jimbowley notifications@github.com wrote:

Thanks for this library,

Should I be able to use both this and external interrupts together?

just including this library with my code causes compile error. I'm using a ProMicro (Leonardo) and IDE 1.8.1

include

include

include

//#include

define pinA1 1 //Roller A

define pinZ1 8 //Spinner

long cntX=0; //counter for mouse X-axis long lastcntX=0; float realX=0; float incX= 0.5; // This gives approx correct speed on missile command default sensitivity 20 float incZ= 0.1; // high resolution spinner needs low value here.

void setup() {

// pinMode(pinZ1, INPUT_PULLUP); // enableInterrupt(pinZ1,doZCount, CHANGE);

pinMode(pinA1, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(pinA1),doACountX,CHANGE);

Mouse.begin(); Keyboard.begin(); }

void loop() { //send mouse update to usb cntX = realX; if(cntX!=lastcntX ){ Mouse.move((cntX-lastcntX),0); lastcntX=cntX; } }

void doZCount() { // spinner is moving realX = realX +incZ; }

void doACountX() { // ball is moving realX = realX +incX; }

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/GreyGnome/EnableInterrupt/issues/53, or mute the thread https://github.com/notifications/unsubscribe-auth/ADSimZGLojEY6OcV3TWg9XOc5y7d4-ZNks5umlSRgaJpZM4Xxi6u .

-- -Mike Schwager

GreyGnome commented 5 years ago

enableInterrupt() chooses the proper interrupt type for the pin you are using.

On Thu, Dec 20, 2018 at 7:02 AM happysupply notifications@github.com wrote:

Same problem here. Tried compiling for Uno with both external and PinChange interrupts, through functions attachInterrupt() and enableInterrupt(). This didn't work.

When I replaced the attachInterrupts for enableInterrupts, the code did compile.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/GreyGnome/EnableInterrupt/issues/53#issuecomment-448992257, or mute the thread https://github.com/notifications/unsubscribe-auth/ADSimUdsIA4cclgXS9Mns6-A_2OuT9eVks5u64plgaJpZM4Xxi6u .

-- -Mike Schwager

GreyGnome commented 5 years ago

If you are saying that you are attempting to use both enableInterrupt() and attachInterrupt(), that's not supported. Just use enableInterrupt(). External interrupts will be selected on pins that support them.

On Wed, Dec 19, 2018 at 1:06 AM Mihai Bob notifications@github.com wrote:

I am not able to run this with external interrupts as well. With the deprecated library I was able to do so. I am now wondering if this is a bug?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/GreyGnome/EnableInterrupt/issues/53#issuecomment-448491431, or mute the thread https://github.com/notifications/unsubscribe-auth/ADSimZD0IETNHlFJ3OjKqgT8GedaOmiBks5u6eV6gaJpZM4Xxi6u .

-- -Mike Schwager

happysupply commented 5 years ago

Hi Mike, many thanks for your quick reply. When I replaced attachInterrupt() with enableInterrupt(), I was worried that the interrupt trigger on (UNO) pins 2 and 3 were slowed down (because enableInterrupt is slower). Your answer clarifies I shouldn't worry about this.

Problem is solved now, as far as I'm concerned!

GreyGnome commented 5 years ago

enableInterrupt() is just the attachment mechanism. I think you're concerned that it uses Pin Change Interrupts where it doesn't need to. But it will happily choose External Interrupts where it can. :-)

On Mon, Dec 24, 2018 at 2:11 AM happysupply notifications@github.com wrote:

Hi Mike, many thanks for your quick reply. When I replaced attachInterrupt() with enableInterrupt(), I was worried that the interrupt trigger on (UNO) pins 2 and 3 were slowed down (because enableInterrupt is slower). Your answer clarifies I shouldn't worry about this.

Problem is solved now, as far as I'm concerned!

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/GreyGnome/EnableInterrupt/issues/53#issuecomment-449700680, or mute the thread https://github.com/notifications/unsubscribe-auth/ADSimTf3Qul8kJ0b5NrZZEpFkMnabRmAks5u8IxBgaJpZM4Xxi6u .

-- -Mike Schwager

happysupply commented 5 years ago

Exactly, that was my concern. Good to hear I shouldn't be concerned indeed. Many thanks again and happy holidays:)

GreyGnome commented 5 years ago

Closing this as not an issue. :-)