fade error

my board is the uno r3 and I am trying to get my rgb led to fade into each color. so I copied of my fade led project with just one color :

int led=9;

void setup()
{

pinMode(led, OUTPUT);

}

void loop()
{

for (int fade=0; fade <=255; fade=fade+5)
{

analogWrite (led, fade);
delay (30);

}
}

and the fade rgb i am working on now

int red=9;
int green=10;
int blue=11;

void setup() {
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);

}

void loop() {
for (int fade=0; fade <=100; fade=fade+5);

analogWrite (red, fade);
delay(30);
digitalWrite(red, 0); analogWrite (green, fade);
delay(30);
digitalWrite(green, 0); analogWrite (blue, fade);
delay(30);
digitalWrite(blue, 0);

}

I do not know what is wrong please tell me and if you know a code for this can you send it to me (you can pm me) fade was not declared in this scope

Please post your code inside code tags. It makes it easier for people to help you. Also, format your code (Ctrl-T in the IDE) so thing align properly.

If you do those things, you will see all the code you think is associated with the for() loop is actually NOT connected to it at all since you have a trailing ';' on that line which marks the end of the for() loop.

Hi,
If you want to fade RED up then OFF, then GREEN up then OFF, then BLUE up then OFF.
The simplest way is to write three separate for loops one after the other, one loop for each colour.
Your code as posted, has a { missing.

Your current for loop, is trying to make ALL the LEDs go up 5 then down to 0, then next loop up to 10 and back to 0.

To turn your LED off, use analogWrite(ledpin, 0) rather than digitalWrite.

Tom... :slight_smile:
PS. You can use an array to keep the number of loops to a minimum, but lets get your basic code working first.