// A small sketch for fun.
#define NUM_ROWS 32
// The number of pins is half the number of rows.
#define NUM_PINS (NUM_ROWS/2)
int row;
int ledPins[NUM_PINS] = {13,12,11,10,9,8,7,6,5,4,3,2,A0,A1,A2,A3};
void setup()
{
Serial.begin(115200);
for(int pin=0; pin<NUM_PINS; pin++)
{
pinMode(ledPins[pin],INPUT);
}
// Set the "previous" row to the last one,
// so the first one will turn on first.
row = NUM_ROWS - 1;
}
void loop()
{
// Turn off the previous row.
int oldPin = row % NUM_PINS;
pinMode(ledPins[oldPin],INPUT);
// Advance the row.
row++;
if(row >= NUM_ROWS)
row = 0;
int newPin = row % NUM_PINS;
// Turn on new row.
// Either drive the Anode or the Cathode.
if(row >= NUM_ROWS/2)
{
digitalWrite(ledPins[newPin],LOW);
pinMode(ledPins[newPin],OUTPUT);
}
else
{
digitalWrite(ledPins[newPin],HIGH);
pinMode(ledPins[newPin],OUTPUT);
}
// Delay.
delay(300);
}