I have a simple setup with a problem. I have a single RGB LED, common ground, connected and working properly. When I add a servo, the LED stops illuminating. The program is running correctly, because I am getting debug information and the servo works. It's just that the LED stop illuminating.
I have tried two different Arduino boards, and two different servos, with the same results. The LED stops working when I try to attach the servo to a pin. Regardless of the pin. Comment out "servoWings.attach(6)" and the LED works properly. Understandably, though, the servo won't work without that. Any ideas?
Here is my code:
#include <Servo.h>
// pins for RGB LED
const int RED = 9;
const int GREEN = 10;
const int BLUE = 11;
// declare on object for the servo
Servo servoWings;
int initFlag = 0;
void setup() {
// put your setup code here, to run once:
servoWings.attach(6);
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
setLevel(0);
Serial.println("Off");
servoWings.write(100);
delay(1000);
servoWings.write(0);
delay(1000);
setLevel(1);
Serial.println("Yellow");
}
void setLevel(int level) {
if (level == 0) {
analogWrite(RED, 0);
analogWrite(GREEN, 0);
analogWrite(BLUE, 0);
} else if (level == 1) {
analogWrite(RED, 500);
analogWrite(GREEN, 125);
analogWrite(BLUE, 0);
}
}