Is this a bug in the controller or 'Servo.h' library?

Long story short, for this project I am using an UNO board, the board is controlling one servo, and four LED’s…

The LED’s are on I/O’s 5,6,9,10, and all use PWM to simulate a gradual on/off fade, as would be seen with large incandescent bulbs. The servo is attached to ‘A0’.

Anyways, the servo code works perfectly and PWM code for LED’s on pins 5 and 6 work perfectly…

Here is the supposed bug:

The PWM on pins 9 and 10 work fine too until I try to call this ‘Servo.h’ attach function:

myservo.attach(A0);

If I omit this from my code, the LED’s on pins 5,6,9,10 work just fine, but if I call the servo attach function then the PWM on pins 9 and 10 stop working, and these LED’s only flash for a fraction of a second once the PWM value hits 255. Keep in mind that pins 5 and 6 aren’t affected by this and always function, it is only pins 9 and 10 that don’t cooperate.

FYI, I did not test pins 3 or 11 for this issue because my project does not use them, but I assume pin 3 will work and pin 11 will glitch. I posted examples of the working and non working code below. Only difference in the code is a single line is omitted/commented-out. Obviously, in my real program I need to call the servo attach function to make the servo work, but this example code addresses only LED’s. Please let me know if there is a fix for this or if it is an error I am making. Thanks!

Here is an example of the working code that pulses the LED’s:

=============================

#include <Servo.h>

Servo myservo; // create servo object to control a servo

int bright = 0; // How bright the LED is lit through PWM.

void setup()
{
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
}

void loop()
{
for(bright = 0; bright <= 255; bright += 1) // Changes LED brightness from 0 to 255;
{
// myservo.attach(A0); // ALL LED’s PULSE PROPERLY AND WORK WHEN THIS IS DISABLED.

analogWrite(5, bright);
analogWrite(6, bright);
analogWrite(9, bright);
analogWrite(10, bright);

delay(2);
}
bright = 0;
delay(500);
}

=============================

Here is an example of the NON working code where pin’s 9 and 10 don’t pulse properly:

=============================
#include <Servo.h>

Servo myservo; // create servo object to control a servo

int bright = 0; // How bright the LED is lit through PWM.

void setup()
{
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
}

void loop()
{
for(bright = 0; bright <= 255; bright += 1) // Changes LED brightness from 0 to 255;
{
myservo.attach(A0); // PWM on pins 9 and 10 won’t work now. Pins 5 and 6 still work fine.

analogWrite(5, bright);
analogWrite(6, bright);
analogWrite(9, bright);
analogWrite(10, bright);

delay(2);
}
bright = 0;
delay(500);
}

=============================

RTFM

The Servo library supports up to 12 motors on most Arduino boards and 48 on the Arduino Mega. On boards other than the Mega, use of the library disables analogWrite() (PWM) functionality on pins 9 and 10, whether or not there is a Servo on those pins. On the Mega, up to 12 servos can be used without interfering with PWM functionality; use of 12 to 23 motors will disable PWM on pins 11 and 12.

I think Servo Attach only works with digital pins.

I think Servo Attach only works with digital pins.

You think incorrectly.

Ok. Thanks for the clarification.

My bad,

thanks for the info!