Right.
Here's a video link: Single LED at a time with other "planes" lit - YouTube with a trivial sketch demonstrating the problem plus the code driving it:
#include <avr/pgmspace.h> // allows use of PROGMEM to store patterns in flash
#define CUBESIZE 4
#define PLANESIZE CUBESIZE*CUBESIZE
/*
** Defining pins in array makes it easier to rearrange how cube is wired
** Adjust numbers here until LEDs flash in order - L to R, T to B
*/
int LEDPin[] = {A1, A0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
int PlanePin[] = {19, 18, 17, 16};
// initialization
void setup()
{
int pin; // loop counter
// set up LED pins as output (active HIGH)
for (pin = 0; pin < PLANESIZE; pin++) {
pinMode( LEDPin[pin], OUTPUT );
}
// set up plane pins as outputs (active HIGH)
for (pin = 0; pin < CUBESIZE; pin++) {
pinMode( PlanePin[pin], OUTPUT );
}
//seeding random for random pattern
randomSeed(analogRead(10));
}
/*
With the anode leg set up, you need to digitalWrite the pin to HIGH, setting it to 5 volts
led high = on
led low = off
and set the transistor's base to high to switch the cathode "plane" layer to drain collect in the one side
and emit to ground, i.e. creating a potential difference and causing current to flow
plane high = on
plane low = off
*/
void turnEverythingOff()
{
for (int i = 0; i < PLANESIZE; i++)
{
digitalWrite(LEDPin[i], LOW);
}
for (int i = 0; i < CUBESIZE; i++)
{
digitalWrite(PlanePin[i], LOW);
}
}
void loop()
{
turnEverythingOff();
//straight up cycle through cube, 1 led at a time
for (int j = 0; j < CUBESIZE; j++) {
for (int i = 0; i < PLANESIZE; i++) {
digitalWrite(LEDPin[i], HIGH);
digitalWrite(PlanePin[j], HIGH);
delay(500);
digitalWrite(LEDPin[i], LOW);
digitalWrite(PlanePin[j], LOW);
}
}
}
Here's the same circuit wired up with slightly different code where I by default have pinmode on each pin to input until I use it: Single LED at a time - YouTube
#include <avr/pgmspace.h> // allows use of PROGMEM to store patterns in flash
#define CUBESIZE 4
#define PLANESIZE CUBESIZE*CUBESIZE
/*
** Defining pins in array makes it easier to rearrange how cube is wired
** Adjust numbers here until LEDs flash in order - L to R, T to B
*/
int LEDPin[] = {A1, A0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
int PlanePin[] = {19, 18, 17, 16};
// initialization
void setup()
{
int pin; // loop counter
// set up LED pins as output (active HIGH)
for (pin = 0; pin < PLANESIZE; pin++) {
//xxx commented out as a work around to the problem
//pinMode( LEDPin[pin], OUTPUT );
}
// set up plane pins as outputs (active HIGH)
for (pin = 0; pin < CUBESIZE; pin++) {
pinMode( PlanePin[pin], OUTPUT );
}
//seeding random for random pattern
randomSeed(analogRead(10));
Serial.begin(9600);
}
/*
With the anode leg set up, you need to digitalWrite the pin to HIGH, setting it to 5 volts
led high = on
led low = off
and set the transistor's base to high to switch the cathode "plane" layer to drain collect in the one side
and emit to ground, i.e. creating a potential difference and causing current to flow
plane high = on
plane low = off
*/
void turnEverythingOff()
{
for (int i = 0; i < PLANESIZE; i++)
{
digitalWrite(LEDPin[i], HIGH);
//xxx Hack to block circuit close?
pinMode(LEDPin[i], INPUT);
}
for (int i = 0; i < CUBESIZE; i++)
{
digitalWrite(PlanePin[i], LOW);
}
}
void loop()
{
turnEverythingOff();
//straight up cycle through cube, 1 led at a time
for (int j = 0; j < CUBESIZE; j++) {
for (int i = 0; i < PLANESIZE; i++) {
//xxx hack to change pinmode each time
pinMode(LEDPin[i], OUTPUT);
digitalWrite(LEDPin[i], HIGH);
digitalWrite(PlanePin[j], HIGH);
while (Serial.available() <= 0) {
delay(500);
}
byte incomingByte = Serial.read();
digitalWrite(LEDPin[i], LOW);
//xxx hack to change pinmode each time
pinMode(LEDPin[i], INPUT);
digitalWrite(PlanePin[j], LOW);
}
}
}
Looking for understanding of what's up...