// Modified Version of the LED matrix example of the Arduino IDE.
// It can address 8x8 LEDs individually, but only one at a time. However, because
// the LEDs do "afterglow" it is possible to have apparently many or all lit
// at the same time, depending on delay / refresh rate (see remarks in code).
// by Dieter Marfurt 2023
// 2-dimensional array of row pin numbers:
const int row[8] = {
2, 7, 19, 5, 13, 18, 12, 16
};
// 2-dimensional array of column pin numbers:
const int col[8] = {
6, 11, 10, 3, 17, 4, 8, 9
};
// cursor position:
int ox=0; // old plot position
int oy=0;
float angle=0;
int ra=0;
int wx=0;
int wy=0;
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);
}
}
void loop() {
handle_LEDmatrix();
}
void handle_LEDmatrix() {
// a "radar" effect
wx=3.5+sin(angle)*(1+ra); // determine where to draw next pixel
wy=3.5+cos(angle)*(1+ra);
if(wx<0){wx=0;} // limit to "onscreen"
if(wx>7){wx=7;}
if(wy<0){wy=0;}
if(wy>7){wy=7;}
digitalWrite(row[ox], LOW);// source off // turn last pixel off
digitalWrite(col[oy], HIGH); // sink off
digitalWrite(row[wx], HIGH);// source on // draw new pixel
digitalWrite(col[wy], LOW); // sink on
delay(3); // the shorter this delay, the more LEDs will afterglow.
ox=wx; // remember new pixel
oy=wy;
ra++; // progress animation variables
if(ra>3)
{
ra=0;
angle+=0.1;
if(angle>=360)angle=0;{}
}
// allowing apparently multiple leds to be lit, where only one is on at any time.
// A more serious implementation would use source for both, rows and cols, to
// trigger mosfets at the Vcc and Gnd of them. A capacitor per LED could enhance the
// afterglow, charged by a strong mosfet pulse, but the LED can drain it only through a resistor.
// Or latches could be used for every LED, which are addressed by row/col.
}