Led fading with 9 and 8 pins? [noob]

Hi everyone! Here’s my brand new Arduino!
Just trying to make something simple waiting for buying some interesting components.

I wish to fade a led using pin 9 and connecting it to the 8 pin as ground. Is it possible?

const int LED = 9;
int i = 0;

void setup()
{
  pinMode(LED, OUTPUT);
  digitalWrite(8,LOW);
}

void loop()
{
  for(i=0;i<255;i++) {
    analogWrite(LED,i);
    delay(10);
  }
  for(i=255;i>0;i--) {
    analogWrite(LED,i);
    delay(10);
  }
}

You'll need pinMode(8, OUTPUT) in your setup too, then it should work..but why not just connect the LED to ground?

Chris

Oh yes, now it works! I thought that "OUTPUT" was for sending something only. Thanks!

Well, I didn't find any wire at the moment of the question, I was only able to put the led on a real close pin (short legs, found led!)

:cold_sweat:

Haha that makes sense.

“OUTPUT” is for sending something, but that’s what you’re doing – you’re sending ground!

Glad it’s working. Good luck exploring!

Chris

you could even get all CRAZY! and use a bipoler / duel color LED, and have it fade between the LED’s two colors in this way I do believe. those work by swapping the polarity between the legs.