Using servo library and ISR(TIMER1_COMPA_vect) in the same sketch

Hello there,

I spent a lot of time without success to found a solution for this:

The first thing that my sketch do is read a digital pin to know which mode user wants to run. IE:

if (digitalRead(x) = 0) = mode_A

or

if (digitalRead(x) = 1) = mode_B

Ok

If "mode_A" is selected, I need to use <Servo.h>. No problem, I can include it a "if" in Setup{} section.

If "mode_B" is selected, I need to use the "ISR(TIMER1_COMPA_vect)" vector. With multiple variables.

Servo library cannot be used at the same time with "ISR(TIMER1_COMPA_vect)" because both use TIMER1.

Note1: "mode_A" does not need to redefine ISR vector and "mode_B" does not need to use servo library.

Note2: My "mode_A" sketch works well and my "mode_B" sketch works well too. I need to put it together with the digitalRead mode selection.

Note3: I use Pro Mini equivalent à 8MHZ.

I tried ServoTimer2 library but it is made for 16Mhz speed and my skill in library and Timers is not enough good. :o

I tried to put ISR function in a library but with 4-5 variables to pass, it is hard for me. And I read some posts with conditional "include" problem in IDE.

Thank a lot for your help! :slight_smile:

I tried to put ISR function in a library

In the hope that doing so would make it use a different timer? Is that even a reasonable thing to do?

I need to use the "ISR(TIMER1_COMPA_vect)" vector. With multiple variables.

This doesn't make sense. The timer ticked the required number of times, or it didn't. How do you plan to use multiple variables with that?

I tried ServoTimer2 library but it is made for 16Mhz speed

It defaults to 16MHz. You could change that.

my skill in library and Timers is not enough good.

Then this project is not for you.