My first Arduion test: 10 LEDs running light

2009 April 24

Check this out:
YouTube Preview Image

That my first proper Arduino test, controlling a 10 LED running light. I attached a small button via interrupt as well to start & stop the light. More to come soon, stay tuned!

Here the (very,very ugly) source code:

int ledPin = 3;      // First LED connected to digital pin 13
volatile int stop = LOW;

void setup()
{
  Serial.begin(38400);
  for( int i = 0; i < 10; i++) {
     pinMode(ledPin + i, OUTPUT);
  }
   attachInterrupt(0, stopit, RISING);    //Button attached to Pin 2
}

int i = 0;
void loop()
{
    for( i = 0; i < 7 && !stop; i++) {
      blink(ledPin + i);
    }
    for( i; i >= 1 && !stop; i--) {
      blink(ledPin + i);
    }
    for( i = 0; i < 10 && !stop; i++) {
      blink(ledPin + i);
    }
    for( i; i >= 3 && !stop; i--) {
      blink(ledPin + i);
    }
    for( i; i < 10 && !stop; i++) {
      blink(ledPin + i);
    }
    for( i = 9; i >= 1 && !stop; i--) {
      blink(ledPin + i);
    }
}

void stopit()
{
  delayMicroseconds(1000);
  stop = !stop;
}

void blink( int pin ) {
      digitalWrite(pin, HIGH);
      delay(120 - abs( pin - 8 ) * 20);
      digitalWrite(pin, LOW);
}
No comments yet

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS