Loading...
Pages: [1]   Go Down
Author Topic: If statement doesn't work for me...  (Read 326 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 40
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi. I'm confused so you can probably help me. I made a 32x8 LED board and started working with it.
Code:
//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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1,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,1,1,1,1,1,1,1,0,0,1,1,0,0,0,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,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.
Code:
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?
Code:
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++;
  }
}
« Last Edit: January 20, 2013, 08:36:31 pm by Y2K986 » Logged

Queens, New York
Offline Offline
Edison Member
*
Karma: 31
Posts: 1733
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No multi-posting!

What is the counter after the second print? Does it go past 160?
« Last Edit: January 20, 2013, 08:42:20 pm by HazardsMind » Logged

UNO, MEGA, NANO, 4x4 keypad, micro servos, RF transceivers, bluetooth, ultrasonic sensor, 20x4 I2C LCD, 3.2 TFT touch screen, L298N Dual motor driver, Voice Recognition 15W

"If your doing nothing, it does not mean your lazy, it just means your open for anything that suits you" - Unknown

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 47
Posts: 2575
"We're a proud service of the Lost Electricity Reclamation Agency"
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
« Last Edit: January 20, 2013, 08:55:38 pm by Jack Christensen » Logged

Get the infamous "One Million Ohms" board at tINDIE.com: http://tinyurl.com/BuyMohms

Offline Offline
Newbie
*
Karma: 0
Posts: 40
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

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.
Good idea. Will try!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 40
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you for your help. I changed the code to this:
Code:
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. smiley
Logged

Grand Blanc, MI, USA
Offline Offline
Faraday Member
**
Karma: 47
Posts: 2575
"We're a proud service of the Lost Electricity Reclamation Agency"
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Way to go!
Logged

Get the infamous "One Million Ohms" board at tINDIE.com: http://tinyurl.com/BuyMohms

SF Bay Area (USA)
Offline Offline
Faraday Member
**
Karma: 80
Posts: 5513
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
int Je[8][5] ={
{0b10000000,0b00000000,0b11111110,0b01111111,0b00000000},
You still have 8bit quantities (apparently) in 16-bit variables...
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 40
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?  smiley-red
Logged

Global Moderator
UK
Online Online
Brattain Member
*****
Karma: 143
Posts: 19380
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
byte Je[8][5] ={
{0b10000000,0b00000000,0b11111110,0b01111111,0b00000000},
would seem to do the trick
Logged

Pete, it's a fool looks for logic in the chambers of the human heart.

Offline Offline
Newbie
*
Karma: 0
Posts: 40
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Johannesburg UTC+2
Offline Offline
Edison Member
*
Karma: 34
Posts: 1705
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Sorry, couldn't resist that....  smiley-cool
Logged

IT Crowd:
Roy... "Have you tried turning it off and on again?"
Moss.. "Have you tried forcing an unexpected reboot?"

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 336
Posts: 36476
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 40
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 40
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh...sry..  smiley-red Did not see that ! Thank you smiley
Logged

Pages: [1]   Go Up
Print
 
Jump to: