Problem with Integer in a function

Hello, I’m now searching for more then a week abaout a solution and couldn’t find anything.

If I use the int directly in the function like text = 46 the function is working well.

void funcMatrixShow()
{
  byte matrixShow[8];
  byte r;
  int test=46;
  for (int i = 0; i < 8; i++)
  {
    matrixShow[i] = font5x7[test][i];
  }
  for (int i = 0; i < 8; i++)
  {
    lc.setRow(0, i, matrixShow[i]);
  }
}

If I want to coll the function with the parameter it doesn’t work anymore:

void loop(){
...
funcMatrixShow(46);
...
}

void funcMatrixShow(int test)
{
  byte matrixShow[8];
  byte r;
  for (int i = 0; i < 8; i++)
  {
    matrixShow[i] = font5x7[test][i];
  }
  for (int i = 0; i < 8; i++)
  {
    lc.setRow(0, i, matrixShow[i]);
  }
}

Does anyone hve an Idea what could be the problem?

Why don't you post your code, any error messages, and your observations?

"It doesn't work" doesn't cut it here.

Hi, I thought the problem should be in this part, but now I am not sure anymore.

I want to show some signs on a 8x8 LED Matrix. In the array font5x7 are the information for the signes.

This ist the program working (picture working is a 7):

#include "LedControl.h"

LedControl lc = LedControl(12, 11, 10, 1); // Pins: DIN,CLK,CS, # of Display connected

unsigned long delayTime = 1; // Delay between Frames

void setup()
{
  lc.shutdown(0, false);
  lc.setIntensity(0, 5);
  lc.clearDisplay(0);
}


//  Take values in Arrays and Display them
void funcMatrixShow(int test)
{
  byte matrixShow[8];
  for (int i = 0; i < 8; i++)
  {
    matrixShow[i] = font5x7[test][i];
  }
  for (int i = 0; i < 8; i++)
  {
    lc.setRow(0, i, matrixShow[i]);
  }
}

void funcMatrixShowRand()
{
  byte r;
  for (int i = 0; i < 8; i++)
  {
    r = random(255);
    lc.setRow(0, i, r);
  }
}

void loop()
{
  int v;
  int b[] = {46, 20, 24, 95, 18, 23, 14, 16, 25, 19, 37, 16, 16, 24, 95, 16, 18, 14, 23, 22, 20};
  //for (int g = 0; g < 21; g++)
  //{
    for (int f = 0; f < 100; f++) {
      funcMatrixShow(b[5]);  //static definition of sign.
      delay(delayTime * 30);
      // Put #2 frame on both Display
      //funcMatrixShowRand();
      delay(delayTime);
    }
  //}
}

If I now want to change the signes bei a for-loop the matrix is showing something, but nothing like a signe. (Picture notWorking)

[code]#include "LedControl.h"

LedControl lc = LedControl(12, 11, 10, 1); // Pins: DIN,CLK,CS, # of Display connected

unsigned long delayTime = 1; // Delay between Frames

void setup()
{
  lc.shutdown(0, false);
  lc.setIntensity(0, 5);
  lc.clearDisplay(0);
}


//  Take values in Arrays and Display them
void funcMatrixShow(int test)
{
  byte matrixShow[8];
  for (int i = 0; i < 8; i++)
  {
    matrixShow[i] = font5x7[test][i];
  }
  for (int i = 0; i < 8; i++)
  {
    lc.setRow(0, i, matrixShow[i]);
  }
}

void funcMatrixShowRand()
{
  byte r;
  for (int i = 0; i < 8; i++)
  {
    r = random(255);
    lc.setRow(0, i, r);
  }
}

void loop()
{
  int v;
  int b[] = {46, 20, 24, 95, 18, 23, 14, 16, 25, 19, 37, 16, 16, 24, 95, 16, 18, 14, 23, 22, 20};
  for (int g = 0; g < 21; g++)
  {
    for (int f = 0; f < 100; f++) {
      funcMatrixShow(b[g]);  //static definition of sign.
      delay(delayTime * 30);
      // Put #2 frame on both Display
      //funcMatrixShowRand();
      delay(delayTime);
    }
  }

}

void funcMatrixShow(int test)
{

It is completely obvious to anyone with more than 2 gray cells to rub together that that is a function. To anyone with less then 2, the “func” in the name is not going to help. GET RID OF IT!

Why do you keep referring to test as a byte, when clearly is isn’t?

  int v;
  int b[] = {46, 20, 24, 95, 18, 23, 14, 16, 25, 19, 37, 16, 16, 24, 95, 16, 18, 14, 23, 22, 20};
  for (int g = 0; g < 21; g++)
  {
    for (int f = 0; f < 100; f++) {

You REALLY need to get out of the habit of pounding the i, n, and t keys for every variable. Use the APPROPRIATE type, b, g, and f clearly do not need to be ints.

A simple Serial.print() statement in MatrixShow() will tell you whether you are passing the value to the function that you think you are.

Sorry, I didn’t understand what you like to say to me. First I made some new names for the variables, but nothing changed!
Then I searched about the Serial.print(), now I know this little helper, the intresting thing is, the serial consol says both times “46” but the matrix one time shows the wrong dots like I wrote in my last message.

The not working code:

#include "LedControl.h"

LedControl lc = LedControl(12, 11, 10, 1); // Pins: DIN,CLK,CS, # of Display connected

unsigned long delayTime = 1; // Delay between Frames

void setup()
{
  Serial.begin(9600);
  Serial.println("--- Start Serial Monitor SEND_RCVE ---");
  Serial.println(" Type in Box above, . ");
  Serial.println("(Decimal)(Hex)(Character)");
  Serial.println();
  lc.shutdown(0, false);
  lc.setIntensity(0, 5);
  lc.clearDisplay(0);
}


//  Take values in Arrays and Display them
void dMatrixShow(int test)
{
  byte matrixShow[8];
  for (int it1 = 0; it1 < 8; it1++)
  {
  Serial.println(test);
    matrixShow[it1] = font5x7[test][it1];
  }
  for (int it2 = 0; it2 < 8; it2++)
  {
    lc.setRow(0, it2, matrixShow[it2]);
  }
}

void funcMatrixShowRand()
{
  byte r;
  for (int i = 0; i < 8; i++)
  {
    r = random(255);
    lc.setRow(0, i, r);
  }
}

void loop()
{
  int bla[] = {46, 20, 24, 95, 18, 23, 14, 16, 25, 19, 37, 16, 16, 24, 95, 16, 18, 14, 23, 22, 20};
  int countBla2 = 0;
  for (int countBla = 0; countBla < 21; countBla = countBla + 1)
  {
    for (int countFrame = 0; countFrame < 100; countFrame++) {
      dMatrixShow(bla[countBla]);
      delay(delayTime * 300);
      // Put #2 frame on both Display
      //funcMatrixShowRand();
      delay(delayTime);
    }
  }

}

PaulS: It is completely obvious to anyone with more than 2 gray cells to rub together.....

here we go again. @PaulS, when will you realise that some people in this world don't understand English as well as you might, and certainly won't understand colloquialisms like this. If the Op wants to preface a function with 'func' that's up to him/her and has NOTHING to do with the problem, and your comment will only serve to confuse.

@mike285, please ignore Pauls' rude comments. I don't have a LED matix to test, so can't help much, but it may be helpful if you explain how your array b[] is generated.

Thanks for the reply.

I just initialize b[] like this: (now I just have changed the name to bla[])

int bla[] = {46, 20, 24, 95, 18, 23, 14, 16, 25, 19, 37, 16, 16, 24, 95, 16, 18, 14, 23, 22, 20};

Yes, I see how it is initialised, but I meant how did you calculate the numbers? Where did they come from?

An educated guess: font5x7[][] is in PROGMEM. If this is the case, you need

matrixShow[it1] = pgm_read_byte(&font5x7[test][it1]);

Also, I believe it is supposed to display "N48°27.093E008°02.764".

Thanks, now I have managed the Problem and you're right, but the coordinates don't make any sence at the moment.