hi!
i started out with the basic charlyplex example and extended it further and further. but very quickly i ran into funny problems. patterns going out of whack. multiplexed letters not looking right etc. i continued simplifying the code because i thought i had a problem with pointers and function-calling, which just moved the funk somewhere else.
i called my local C-guru and he cannot find any fault.
the latest version actually seems to crash in the third iteration of the loop o_0
can anyone please look at this code and tell me how to debug this?
void setup() {
// initialize the digital pin as an output.
}
// the loop routine runs over and over again forever:
void loop() {
repeatski:
//should spell HAI, then go blank
Letter ( "x xx xxxxxx xx x", 500);
Letter ( " xx x xx xxxxxx x", 500);
Letter ( " xxx x x x xxx", 500);
Letter ( " ", 1000);
//should turn each LED on once
Letter ( "x ", 500);
Letter ( " x ", 500);
Letter ( " x ", 500);
Letter ( " x ", 500);
Letter ( " x ", 500);
Letter ( " x ", 500);
Letter ( " x ", 500);
Letter ( " x ", 500);
Letter ( " x ", 500);
Letter ( " x ", 500);
Letter ( " x ", 500);
Letter ( " x ", 500);
Letter ( " x ", 500);
Letter ( " x ", 500);
Letter ( " x ", 500);
Letter ( " x ", 500);
Letter ( " x ", 500);
Letter ( " x ", 500);
Letter ( " x ", 500);
Letter ( " x", 500);
//shut down matrix and wait so i can see a pattern
LEDoff();
delay(2000);
goto repeatski;
}
void Letter ( char disp[25], long duration ) {
int steptime = 1;
int tick = 0;
redo:
//see if we need to do all this again or if we are done
if (duration <= 20) {return;} //20 because there are 20 LEDs. prevents duration running negative.
tick = 0;
//run through displaying the matrix once as fast as possible
if (disp[ 0] != ' ') { LEDon(0, 4); delay(steptime); tick++;}
if (disp[ 1] != ' ') { LEDon(0, 3); delay(steptime); tick++;}
if (disp[ 2] != ' ') { LEDon(0, 2); delay(steptime); tick++;}
if (disp[ 3] != ' ') { LEDon(0, 1); delay(steptime); tick++;}
if (disp[ 4] != ' ') { LEDon(1, 4); delay(steptime); tick++;}
if (disp[ 5] != ' ') { LEDon(1, 3); delay(steptime); tick++;}
if (disp[ 6] != ' ') { LEDon(1, 2); delay(steptime); tick++;}
if (disp[ 7] != ' ') { LEDon(1, 0); delay(steptime); tick++;}
if (disp[ 8] != ' ') { LEDon(2, 4); delay(steptime); tick++;}
if (disp[ 9] != ' ') { LEDon(2, 3); delay(steptime); tick++;}
if (disp[10] != ' ') { LEDon(2, 1); delay(steptime); tick++;}
if (disp[11] != ' ') { LEDon(2, 0); delay(steptime); tick++;}
if (disp[12] != ' ') { LEDon(3, 4); delay(steptime); tick++;}
if (disp[13] != ' ') { LEDon(3, 2); delay(steptime); tick++;}
if (disp[14] != ' ') { LEDon(3, 1); delay(steptime); tick++;}
if (disp[15] != ' ') { LEDon(3, 0); delay(steptime); tick++;}
if (disp[16] != ' ') { LEDon(4, 3); delay(steptime); tick++;}
if (disp[17] != ' ') { LEDon(4, 2); delay(steptime); tick++;}
if (disp[18] != ' ') { LEDon(4, 1); delay(steptime); tick++;}
if (disp[19] != ' ') { LEDon(4, 0); delay(steptime); tick++;}
//done, now turn matrix off so we don't leave any residue pixel on
LEDoff();
//if no LED was on, tick will be zero. then recursion cannot be used, so just sleep for the requested duration and be done
if (tick == 0) {
delay(duration);
return;
}
else { //otherwise reduce the requested duration by the number of ticks already done
duration = duration - (tick * steptime);
// Letter(disp, duration);
goto redo;
return;
}
}
void LEDon(int vin, int gnd) {
pinMode(0, INPUT);
pinMode(1, INPUT);
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(4, INPUT);
// pinMode(5, INPUT);
pinMode(vin, OUTPUT);
pinMode(gnd, OUTPUT);
digitalWrite(vin, HIGH);
digitalWrite(gnd, LOW);
}
void LEDoff() {
//original code
/* pinMode(0, INPUT);
pinMode(1, INPUT);
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(5, INPUT); */
//alternative - did not fix the problem
for (int i = 0 ; i < 5 ; i++) {
pinMode(i, OUTPUT);
digitalWrite(i, LOW);
}
}