system
December 3, 2011, 11:47am
1
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);
}
}
system
December 3, 2011, 4:24pm
2
You'll need pinMode(8, OUTPUT) in your setup too, then it should work..but why not just connect the LED to ground?
Chris
system
December 3, 2011, 7:50pm
3
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!)
system
December 3, 2011, 7:54pm
4
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
system
December 3, 2011, 10:54pm
5
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.