Sunday, October 4, 2015

Sequential flasher using arduino and 14 LED

This is simple flasher with 14 LEDs. you can decrease the flashing speed by changing number "100" in first line of program code to "500" for example.
You must protect your LEDs by putting a 150 ohm resistor through GND line.

Sequential flasher using arduino and 14 LED


Code:

int timer = 100;     
int ledPins[] = {
  0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};    
int pinCount = 14;      

void setup() {
  for (int thisPin = 0; thisPin < pinCount; thisPin++)  {
    pinMode(ledPins[thisPin], OUTPUT);    
  }
}

void loop() {
  for (int thisPin = 0; thisPin < pinCount; thisPin++) {
    digitalWrite(ledPins[thisPin], HIGH); 
    delay(timer);                
    digitalWrite(ledPins[thisPin], LOW);  

  }

  for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) {
    digitalWrite(ledPins[thisPin], HIGH);
    delay(timer);
    digitalWrite(ledPins[thisPin], LOW);
  }
}