LED wiring

The Arduino Mega has 54 digital I/O pins, 50 of which are each driving an LED on the Hi-Striker. Each pin can drive up to 40mA, so the only additional components needed are one 100k current-limiting resistor per LED.

For testing, a simple cascading loop runs through the (first 16) LEDs one at a time:

const int ledCount = 16;    // the number of LEDs in the bar graph
int ledPins[] = { 2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17 };   // an array of pin numbers to which LEDs are attached

void setup() {
  // loop over the pin array and set them all to output:
  for (int thisLed = 0; thisLed < ledCount; thisLed++) {
    pinMode(ledPins[thisLed], OUTPUT);
  }
}

void loop() {
  // loop over the LED array:
  for (int thisLed = 0; thisLed < ledCount; thisLed++) {
    digitalWrite(ledPins[thisLed], HIGH);  // turn on the LED
    delay(20);                             // wait
    digitalWrite(ledPins[thisLed], LOW);   // turn off the LED
  }
}

2 Responses to “LED wiring”

  1. Nash writes:

    Thanks alot for the great read.

  2. Jabari writes:

    I wrote a similar blog regarding this subject but your is better. 🙂