Precaution when using RowColumnScanning sketch

In Arduino’s RowColumnScanning sketch, there is a section of code that initialises the output pins. As-is, this code can cause the processor to overheat in the case where the 8x8 LED matrix used has its LEDs wired in the OPPOSITE polarity as the Lumex part mentioned in the example.

The original code:

void setup() {
// initialize the I/O pins as outputs
// iterate over the pins:
for (int thisPin = 0; thisPin < 8; thisPin++) {
  // initialize the output pins:
  pinMode(col[thisPin], OUTPUT);
  pinMode(row[thisPin], OUTPUT);
  // take the col pins (i.e. the cathodes) high to ensure that
  // the LEDS are off:
  digitalWrite(col[thisPin], HIGH);
}

Note that ONLY the state of column pins is initialised but the state of the row pins is not. This is fine >provided< the part’s LEDs have the indicated polarity. However, if a different part is used, one whose LEDs are reversed, ALL of the LEDs will light, drawing too much current from the processor and causing it to overheat. Not good.

This happened to me. I was given a kit from 16Hertz whose LED matrix had the opposite polarity as the Lumex part mentioned in the example.

The solution is trivial to implement: simply initialise BOTH column and row pins to the SAME state. It doesn’t matter which one, as long as they’re the same.

To wit:

void setup() {
// initialize the I/O pins as outputs
// iterate over the pins:
for (int thisPin = 0; thisPin < 8; thisPin++) {
  // initialize the output pins:
  pinMode(col[thisPin], OUTPUT);
  pinMode(row[thisPin], OUTPUT);
  // take BOTH row and col pins high to ensure that
  // the LEDS are off:
  digitalWrite(col[thisPin], HIGH);
  digitalWrite(row[thisPin], HIGH); // <-- Add this line
}

Hope this info is useful.