Problem with getting RGBLED to Change with servo motor. Beginner.


I starting using Arduino and learning C++ today and im trying to get and RGB led to change to a random color every couple of seconds as well as a servo motor moving at the same once the color has changed. So, light change to random color waits for x amount of seconds then the servo will move as the light changes.

Right now the servo moves when and where i want it to but the RGB stays different brightnesses of only the Blue diode.

Cheers to anyone that can help/understand me :D. Its taking a while for me to understand the basics.

int redLedPin = 9;
int greenLedPin = 10;
int blueLedPin = 11;
int pos = 0;

#include <Servo.h>
Servo myservo;

void setup() {
  pinMode(redLedPin, OUTPUT);
  pinMode(greenLedPin, OUTPUT);
  pinMode(blueLedPin, OUTPUT);

void loop() {
  pos = 0;

  analogWrite(blueLedPin, random(0, 255));
  analogWrite(redLedPin, random(0, 255));
  analogWrite(greenLedPin, random(0, 255));
  pos = 180;


Abandon the random function for now and write fixed values to the LEDs. Do they behave as you expect ? How are the LEDs wired ? How is the servo powered ?