RGB LED brightness control with millis

Hi, I am trying to make orange color with RGB LED and fade it in and out with milis. I want the led to change only its brightness while keeping its orange color. How can I do this?

int redpin1 = 6;    // the pin number for the top RGB led
int greenpin1 = 5;
int bluepin1 = 3;

int brightness = 0; //how bright the LED is
int fadeAmount = 5; //how many points to fade the LED by
int fadeInterval = 50; //wait for 30 milliseconds to see the dimming effect

unsigned long previousRGBMillis = 0; // the time when the RGB led last activated
unsigned long currentMillis = 0;    // stores the value of millis() in each iteration of loop()


void setup() {




void loop() {

 currentMillis = millis(); 


void setColor1(int red, int green, int blue){ 
 analogWrite(greenpin1, green);
 analogWrite(bluepin1, blue);


void RGBFade1() {
 if (currentMillis - previousRGBMillis >= fadeInterval){
   previousRGBMillis = currentMillis;
   brightness = brightness + fadeAmount;
   if (brightness == 0 || brightness == 250){
      fadeAmount = -fadeAmount;
setColor1(0, 100, 220);  // How do I maintain this color and only change the brightness??


How to use this forum

Please edit your post, select the code, and put it between [code][/code] tags.

You can do that by hitting the “Code” button above the posting area (It looks like a scroll with < > inside it).

To keep a color constant you should do your fade in the HLS (Hue,Lightness,Saturation) color model and then translate to the RGB (Red,Green,Blue) color model for display. Keep the Hue constant and fade the Lightness from 0 (black) to full brightness. Use full saturation.

Google will let you find information about HLS and RGB color models and how to translate between them.