If statement doesn't work for me...

Hi. I’m confused so you can probably help me. I made a 32x8 LED board and started working with it.

//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
//Pin connected to DS of 74HC595
int dataPin = 11;

int blok[8][40];
int counter=0;

int Aca[8][40] ={
{1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,1,1,1,1,1,0,0,0,0,1,1,1,1,1,0,0,0,0,0},
{0,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,0,0,0,0},
{0,0,1,0,0,0,0,0,0,0,0,1,1,0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,1,1,0,0,0,0},
{0,0,0,1,0,0,0,0,0,0,0,1,1,0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,1,1,0,0,0,0},
{0,0,0,0,1,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0},
{0,0,0,0,0,1,0,0,0,0,0,1,1,1,1,1,1,1,0,0,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0},
{0,0,0,0,0,0,1,0,0,0,0,1,1,0,0,0,1,1,0,0,1,1,1,1,1,1,1,0,0,1,1,0,0,0,1,1,0,0,0,0},
{0,0,0,0,0,0,0,1,0,0,0,1,1,0,0,0,1,1,0,0,0,1,1,1,1,1,0,0,0,1,1,0,0,0,1,1,0,0,0,0}
};

int Je[8][40] ={
{1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0},
{0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0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1,1,0,0,0,1,1,0,0,0,0},
{0,0,0,0,0,0,0,1,0,0,0,0,1,1,1,1,1,0,0,0,1,1,0,0,0,1,1,0,0,1,1,0,0,0,1,1,0,0,0,0}
};

void loop(){
{
  //count up routine
      if (counter>=0 && counter <80)
      {
        Print ( Aca );
      }
      if (counter>=80 && counter < 160)
      {
        Print ( Je );
      }
    /*  if (counter>=160 && counter < 240)
      {
        Print ( Car );
      }  */
      if (counter >= 240)   counter=0;
      counter++;
  }
} 
  
void Print ( int blok[8][40]){
  for (int i = 0; i < 8; i++) {
        digitalWrite(latchPin, 0);
        for (int j = 0; j< 40; j++){
          
          shiftOut(dataPin, clockPin, blok[i][j]); 

        }
        digitalWrite(latchPin, 1);
  }
}
  
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
  // This shifts 8 bits out MSB first, 
  //on the rising edge of the clock,
  //clock idles low

//internal function setup
  int i=0;
  int pinState;
  pinMode(myClockPin, OUTPUT);
  pinMode(myDataPin, OUTPUT);

//clear everything out just in case to
//prepare shift register for bit shifting
  digitalWrite(myDataPin, 0);
  digitalWrite(myClockPin, 0);

  //for each bit in the byte myDataOut?
  //NOTICE THAT WE ARE COUNTING DOWN in our for loop
  //This means that %00000001 or "1" will go through such
  //that it will be pin Q0 that lights. 
  pinState = myDataOut;

    //Sets the pin to HIGH or LOW depending on pinState
    digitalWrite(myDataPin, pinState);
    //register shifts bits on upstroke of clock pin  
    digitalWrite(myClockPin, 1);
    //zero the data pin after shift to prevent bleed through
    digitalWrite(myDataPin, 0);

  //stop shifting
  digitalWrite(myClockPin, 0);
}

Problem is when I want to print 2 matrices, one after another, it all works fine and I get " Aca Je" on my LED board.

void loop(){
{
  //count up routine
      if (counter>=0 && counter <80)
      {
        Print ( Aca );
      }
      if (counter>=80 && counter < 160)
      {
        Print ( Je );
      }
      if (counter >= 160)   counter=0;
      counter++;
  }
}

But when I want to print the 3. one nothing happens, not even a start. Can someone help?

void loop(){
{
  //count up routine
      if (counter>=0 && counter <80)
      {
        Print ( Aca );
      }
      if (counter>=80 && counter < 160)
      {
        Print ( Je );
      }
      if (counter>=160 && counter < 240)
      {
        Print ( Car );
      }  
      if (counter >= 240)   counter=0;
      counter++;
  }
}

No multi-posting!

What is the counter after the second print? Does it go past 160?

Strong possibility you're out of SRAM. Three 8x40 integer arrays require 1920 bytes. If they're only going to hold values of 1 or 0, use the byte data type instead and cut the SRAM requirement in half. Better yet, pack 8 bits into a byte, then each array would only require 40 bytes.

Edit: I see there is a fourth 8x40 array as well. With an ATmega328-based board (Uno, etc.) that's definitely over the 2048 bytes of available SRAM, and all of it is not available to a sketch because the Arduino core uses some. Last I checked, with a minimal sketch, about 1800 bytes or so were available IIRC.

HazardsMind:
No multi-posting!

What is the counter after the second print? Does it go past 160?

It goes back to 0, so the whole process is repeated over and over. When trying to print third one, nothing happens.

Good idea. Will try!

Thank you for your help. I changed the code to this:

int Aca[8][5] ={
{0b10000000,0b00001111,0b10000111,0b11000011,0b11100000},
{0b01000000,0b00011111,0b11001111,0b11100111,0b11110000},
{0b00100000,0b00011000,0b11001100,0b00000110,0b00110000},
{0b00010000,0b00011000,0b11001100,0b00000110,0b00110000},
{0b00001000,0b00011111,0b11001100,0b00000111,0b11110000},
{0b00000100,0b00011111,0b11001100,0b00000111,0b11110000},
{0b00000010,0b00011000,0b11001111,0b11100110,0b00110000},
{0b00000001,0b00011000,0b11000111,0b11000110,0b00110000}
};

int Je[8][5] ={
{0b10000000,0b00000000,0b11111110,0b01111111,0b00000000},
{0b01000000,0b00000000,0b11111110,0b01111111,0b00000000},
{0b00100000,0b00000000,0b00000110,0b01100000,0b00000000},
{0b00010000,0b00000000,0b00000110,0b01111111,0b00000000},
{0b00001000,0b00000000,0b00000110,0b01111111,0b00000000},
{0b00000100,0b00000000,0b00000110,0b01100000,0b00000000},
{0b00000010,0b00000000,0b11111110,0b01111111,0b00000000},
{0b00000001,0b00000000,0b01111100,0b01111111,0b00000000}
};

int Car[8][5] ={
{0b10000000,0b00001111,0b10000111,0b11000111,0b11100000},
{0b01000000,0b00011111,0b11001111,0b11100111,0b11110000},
{0b00100000,0b00011000,0b00001100,0b01100110,0b00110000},
{0b00010000,0b00011000,0b00001100,0b01100110,0b00110000},
{0b00001000,0b00011000,0b00001111,0b11100111,0b11100000},
{0b00000100,0b00011000,0b00001111,0b11100111,0b11110000},
{0b00000010,0b00011111,0b11001100,0b01100110,0b00110000},
{0b00000001,0b00001111,0b10001100,0b01100110,0b00110000}
};

And it all worked fine. :slight_smile:

Way to go!

int Je[8][5] ={
{0b10000000,0b00000000,0b11111110,0b01111111,0b00000000},

You still have 8bit quantities (apparently) in 16-bit variables...

Well...that's all what comes to my mind. I have no idea how to do that in any other way. Can you give me an example of how it's suppose to be done? :blush:

byte Je[8][5] ={
{0b10000000,0b00000000,0b11111110,0b01111111,0b00000000},

would seem to do the trick

OK. But it’s the same like I already did. Is there a better ( optimized ) solution?

if (statement doesn't work for me...)
{
  find a different way of doing it;
}

Sorry, couldn't resist that.... 8)

OK. But it's the same like I already did. Is there a better ( optimized ) solution?

How is byte like int? A byte is half the size of an int.

I don't mind. :slight_smile:
Well, I tried switch-case and I get the same problem. :slight_smile:

Oh...sry.. :blush: Did not see that ! Thank you :slight_smile: