Monday, September 15, 2008

Why!!!!

Ok, this is my personal project update/post for the evening. (Also explains why I'm up at 4 am.)

I've found that adding 15 or more "characters" for the code to go through, totally breaks the matrix. 14 or less, fine. 15 or more, mess. Also 15 screws it up differently than 16+ (15 just freezes the loop, 16+ start creating garbage) What's weird is that there is nothing changed in the code except the length of the array, and the adding of a few more array entries. So I can't figure out why it's breaking like this.

Wanna see what I'm talking about? Sure.

Good

Working from Andrew Parnell on Vimeo.

Bad/Broken

Broken from Andrew Parnell on Vimeo.


And if you care, like last time, code is in the comments.

1 comment:

Andrew S. Parnell said...

Good

const int numPatterns = 14;

int anPins[8] = {18,17,16,15,14,2,3,4};
int cathPins[8] = {5, 6, 7, 8, 9, 10, 11, 12};

byte patterns[numPatterns][8][8] = {{ \
{0,0,0,0,0,0,0,1}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
},{ \
{0,0,0,0,0,0,1,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
},{ \
{0,0,0,0,0,1,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
},{ \
{0,0,0,0,1,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,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,0,0,0,0,0,0,0}, \
{0,0,0,0,0,1,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
},{ \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,1,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
},{ \
{0,0,0,0,0,0,0,0}, \
{0,0,0,1,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
},{ \
{0,0,0,0,0,0,0,0}, \
{0,0,1,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
}};

void setup() {

for (int i = 0; i < 8; i++) {
pinMode(anPins[i], OUTPUT);
pinMode(cathPins[i], OUTPUT);
}
for (int i = 0; i < 8; i++) {
digitalWrite(anPins[i], LOW);
digitalWrite(cathPins[i], HIGH);
}
}

void loop() {
for(int i = 0; i < numPatterns; i++) {
pattern(patterns[i], 200);
}
}

void pattern(byte pat[8][8],unsigned long inc)
{
unsigned long T = millis() + inc;
while(millis() < T) {
for (int i = 0; i < 8; i++) {
digitalWrite(cathPins[i], LOW);
for (int j = 0; j < 8; j++) {
digitalWrite(anPins[j], pat[i][j]);
}
blank();
digitalWrite(cathPins[i], HIGH);
}
}
}

void blank() {
for (int i = 0; i < 8; i++) {
digitalWrite(anPins[i], LOW);
}
}

Bad/Broken
const int numPatterns = 15;

int anPins[8] = {18,17,16,15,14,2,3,4};
int cathPins[8] = {5, 6, 7, 8, 9, 10, 11, 12};

byte patterns[numPatterns][8][8] = {{ \
{0,0,0,0,0,0,0,1}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
},{ \
{0,0,0,0,0,0,1,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
},{ \
{0,0,0,0,0,1,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
},{ \
{0,0,0,0,1,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
},{ \
{0,0,0,1,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
},{ \
{0,0,1,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0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,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
},{ \
{0,0,0,0,0,0,0,0}, \
{0,0,0,1,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
},{ \
{0,0,0,0,0,0,0,0}, \
{0,0,1,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
},{ \
{0,0,0,0,0,0,0,0}, \
{0,1,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
{0,0,0,0,0,0,0,0}, \
}};

void setup() {

for (int i = 0; i < 8; i++) {
pinMode(anPins[i], OUTPUT);
pinMode(cathPins[i], OUTPUT);
}
for (int i = 0; i < 8; i++) {
digitalWrite(anPins[i], LOW);
digitalWrite(cathPins[i], HIGH);
}
}

void loop() {
for(int i = 0; i < numPatterns; i++) {
pattern(patterns[i], 200);
}
}

void pattern(byte pat[8][8],unsigned long inc)
{
unsigned long T = millis() + inc;
while(millis() < T) {
for (int i = 0; i < 8; i++) {
digitalWrite(cathPins[i], LOW);
for (int j = 0; j < 8; j++) {
digitalWrite(anPins[j], pat[i][j]);
}
blank();
digitalWrite(cathPins[i], HIGH);
}
}
}

void blank() {
for (int i = 0; i < 8; i++) {
digitalWrite(anPins[i], LOW);
}
}