error:  variable or field declared void

New with Arduino (X-Mas gift) and I’ve been trying to figure out where my syntax is wrong. Getting:

error: variable or field ‘fade’ declared void

Unsure why this won’t compile. Any help appreciated…

#define RED 11

pinMode(RED, OUTPUT);

void fade(color)
{
  int i = 0;
  for (i = 0; i < 255; i++) {
    analogWrite(color, i);
    delay(10);
  }
  
  for (i = 255; i > 0; i--) {
    analogWrite(color, i);
    delay(10);
  }
}


void setup()
{
 char x[ ]="RED";
 fade(x);
}

void loop()
{

}

You will need to indicate the datatype for color. Something like this...

void fade( byte color )

Remove x from setup and call fade using the #define you declared earlier...

void setup()
{
 fade( RED );
}

Finally, welcome to the forum!

Thanks! Now receiving:

error: expected constructor, destructor, or type conversion before ‘(’ token

and it’s highlighting this line:

pinMode(RED, OUTPUT);

Modified code:

#define RED 11

pinMode(RED, OUTPUT);

void fade(byte color)
{
  int i = 0;
  for (i = 0; i < 255; i++) {
    analogWrite(color, i);
    delay(10);
  }
  
  for (i = 255; i > 0; i--) {
    analogWrite(color, i);
    delay(10);
  }
}


void setup()
{

 fade(RED);
}

void loop()
{

}

Move this...

pinMode(RED, OUTPUT);

...to the beginning of setup...

void setup()
{
  pinMode(RED, OUTPUT);
  fade(RED);
}

Genius! Thanks for the help.

I wish the errors were a little more intuitive.

Final question:

If I add another LED, and do this:

loop()
{
fade ( RED );
fade ( YEL );
}

...they fade sequentially. How can I fade them simultaneously?

Thanks!

Would I create an array of LEDs I want to fade, and pass that to the fade() subroutine? And the fade() would have to be re-coded to accept an array?

Genius!

I certainly appreciate the compliment but "Experienced!" is more accurate. ;)

Thanks for the help.

You are welcome. I hope your Christmas present has been fun so far.

How can I fade them simultaneously?

The general solution is to use something called a "finite state machine". If you continue working with your new Arduino, it's worth learning about them. This is a fairly good place to start... http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay

For this Sketch, I suspect your suggestion...

Would I create an array of LEDs I want to fade, and pass that to the fade() subroutine? And the fade() would have to be re-coded to accept an array?

...will work well and give you an opportunity to learn about arrays and learn more about function parameters.

Some LED fading stuff that may help... http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1206438619/0 http://www.arduino.cc/en/Tutorial/ColorCrossfader http://stackoverflow.com/questions/676133/fade-in-multiple-leds-with-arduino http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1226962662/0#0 http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1235225449/13