Code:
int ledPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
int currentLED = 0;
int dir = 1;
int ledDelay = 65;
void setup()
{
for(currentLED = 0; currentLED < 10; currentLED++)
{
pinMode(ledPins[currentLED], OUTPUT);
}
currentLED = 0;
}
void loop()
{
digitalWrite(ledPins[currentLED], HIGH);
delay(ledDelay);
digitalWrite(ledPins[currentLED], LOW);
currentLED = currentLED + dir;
if(currentLED == 9)
{
dir = -1;
}
if(currentLED == 0)
{
dir = 1;
}
}
Nothings really that complicated. Used an array to save all the pin numbers, and an index to point to the current led. Sadly I didn't have enough wires to connect things properly (I really need to get some wire strippers and a big spool of solid core wire) so I improvised a little with the ground wires :)
~(' ')~

No comments:
Post a Comment