Go Down

Topic: Assistance needed converting my scoreboard code from 7 segment LED to MAX7219 Ma (Read 417 times) previous topic - next topic


Are you interested in understanding why? (I may regret asking that. Explaining why it works now is easy enough, but explaining what was going wrong before could get pretty complicated!)
Very much so yes. I'm believe that simply put "d" in your explanation was the key.

I'm trying to figure out how to put it in scoreboard code to make the scores update now. It will have to wait until I get home from work to test.

Thanks again,


Code: [Select]
void setNumber(byte DIGITS[])
  for (int i = 0; i < 8; i++) 

You passed the wrong thing to the function. You sent it a number but you told the function that this number was actually the start of an array that did not exist. Yes it had the same name as your array of bit patterns but a function has it's own scope, that is the values passed to it are valid only within the function you passed it to. Therefore when you passed the function a number and told the function that the number you passed represented an array, it took you at your word. Because this corresponded to no such number, it still assumed it did and so the upshot was when you used it it essentially dragged junk numbers from stuff that happened to be in that memory location.

By telling the function that the number passed to it represented an index in your array of bit patterns corresponding to how we see numbers represented, which is what we intended, it got the correct bit patterns.
You also note that in using:-
Code: [Select]
You accessed row i of the bit patterns that corresponded to the value of the variable d and thus displayed the number you passed to the function.

Put down like this it looks very complex, but basically you screwed up and made the compiler think the number you were passing to the function was something that it wasn't.

Go Up