Go Down

Topic: Problem with RGB code. (Read 579 times) previous topic - next topic

03coupr

Apr 11, 2012, 11:29 am Last Edit: Apr 11, 2012, 11:32 am by 03coupr Reason: 1
Im using the code below to light up an RGB LED, the green and the red are working but the blue doesn't.

Does anyone know why ?

Thanks

/* RGB Fading Example

*/


int RLedPin = 11;       // Red LED connected to PWM digital 11
int GLedPin = 10;       // Green LED connected to PWM digital 10
int BLedPin =  9;       // Blue LED connected to PWM digital 9
int fadeDelay = 5;
int fadeStep  = 1;

void setup()    {    // do nothing here
}

void loop()    {
 for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=fadeStep){
   analogWrite(RLedPin, fadeValue) ;
   delay(fadeDelay) ;
 }
 for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=fadeStep){
   analogWrite(RLedPin, fadeValue) ;
   delay(fadeDelay) ;
 }
 for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=fadeStep){
   analogWrite(GLedPin, fadeValue) ;
   delay(fadeDelay) ;
 }
 for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=fadeStep){
   analogWrite(GLedPin, fadeValue) ;
   delay(fadeDelay) ;
 }
 for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=fadeStep){
   analogWrite(BLedPin, fadeValue) ;
   delay(fadeDelay) ;
 }
 for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=fadeStep){
   analogWrite(BLedPin, fadeValue) ;
   delay(fadeDelay) ;
 }
}

PaulS

The first thing to check is whether it is a hardware problem or a software problem. Switch the legs of the RGB  LED around. Is the problem confined to a pin, or to a color?

Go Up