Help with my logic/syntax with PWM RGB led

Greetings all.

Can someone steer me right with my program, i’m still trying to work out things.

I have a common anode rgb led, sample programs work great but i tried mine a different simpler way and it’s not doing anything. It’s all wired up on my arduino breadboard correctly, the problem is my code.

I made 6 functions with the purpose of being able to call 1 rgb colour PWM’ing up, down etc for each of the three colours and then tried a simple, ramp up red, delay, ramp up green etc but it’s not doing what i want it to.

Can someone guide me please, here’s my code:

//PWM experiments with pirahna rgb led, common anode
//experimenting with functions to control PWM

int value = 0;                            // red value
int value2 = 0;                          //blue value
int value3 = 0;                          //green value
int red = 9;                           // red led
int blue = 10;                         //blue led
int green = 11;                        //green led



 
void setup() 
{ 
  // nothing for setup 
} 
 
void loop() 

{
  //put main prog here
  //test prog
   redup;
   delay(100);
   greenup;
   delay(100);
   blueup;
   delay(100);
   greendown;
   delay(100);
   reddown;
   delay(100);
   greenup;
   delay(100);
   bluedown;
   delay(100);
   greendown;
   delay(100);
   
  
}

//red functions

//red up
 void redup(){                           //function to increase red
  for(value = 0 ; value <= 255; value+=5) // fade in (from min to max) 
  { 
    analogWrite(red, value);           // sets the red value (range from 0 to 255) 
    delay(30);                            // waits for 30 milli seconds to see the dimming effect 
  }                                       // end function
  
}

//red down

 void reddown(){
  for(value = 255; value >=0; value-=5)   // function to decrease red 
  { 
    analogWrite(red, value); 
    delay(30); 
  }  
}                                           //end function


//blue functions

//blue up

void blueup(){                              //blue increase
  for(value2 = 0; value2<=255; value2+=5)    //value2 hopefully controls the blue led
  {
    analogWrite(blue, value2);
    delay(30);
  }
}                                            //end function

//blue down

void bluedown(){                            //decrease blue
  for(value2 = 255; value2>=0; value2-=5)    //value 2 controls blue
  {
    analogWrite(blue, value2);
    delay(30);
  }
}                                          //end function

//Green functions

//green up

void greenup(){
  for(value3 = 0; value3<=255; value3+=5)
  {
    analogWrite(green, value3);
    delay(30);
  }
}                                          //end function

//green down

void greendown(){
  for(value3 = 255; value3>=0; value3-=5)
  {
    analogWrite(green, value3);
    delay(30);
  }
}                                          //end function

P.S. it’s not commented too well as it’s an experiment. :stuck_out_tongue:

You don't set the pins as outputs. Pins default to inputs.

pinMode (r_g_bPin, OUTPUT);

Do this in setup ()

You dont call your functions correctly either.

redup; should be redup(); :)

redup; should be redup();

{smacks forehead} Gosh! Yes, and of course, it doesn't give a compilation error!

Haha, oops, i can’t believe i forgot to set the pins as output.

Yeah i’m rusty on the old functions, chuckle. Cheers people, i’ll give that a bash and see what happens.

:slight_smile: