Servo library and motor controller library fighting over pins 9 and 10 [solved]

I'm using an Arduino Uno with a Pololu Dual VNH5019 Motor Shield. The library for that motor shield uses pins 9 and 10 as PWM pins, one for each of the two motors it drives.

I'm also using the Uno to control two servo motors, using the Servo library. I found out that the Servo library disables the PWM function on pins 9 and 10, even though I am using pins 11 and 13 to control the two servos.

So both libraries are fighting over pins 9 and 10. The motor shield library lets me re-map all pins but 9 and 10. I can't figure out how to modify it to let me use other pins.

But the Servo library seems to suggest that timer pins other than pins 9 and 10 can be used. It seems that Timer1 uses pins 9 and 10, but Timer2 uses pins 3 and 11, which would work for me. So I want to have the Servo library use Timer2 instead of Timer1. So far, I have not figured out how to do that. Anyone know?

Thank you.

There is another servo library (called servoTimer2) that uses Timer2 which should solve your problem. As far as I recall I downloaded it from here.

...R

Robin2, thanks for suggesting ServoTimer2. I tried it out and it didn't work as a drop-in replacement for Servo.

Then I realized that ServoTimer2 takes microseconds of pulse width instead of degrees like Servo. So I had to write a line of code that would convert the degrees to microseconds:

            posLeft = map(posLeft, 0, 180, 544, 2400);

where 0 degrees equals 544 microseconds and 180 degrees equals 2400 microseconds.

The code now works like a charm. I can now use my two servos (which steer independently the two front wheels of a toy car) and my motor shield (which drives the back wheels) at the same time. Thanks again.