# Problem with if statement controlling 8x8 matrix

I am new to Arduino programming and am having difficulty using an “if” statement to get a selected numeral to display on an 8 x 8 LED matrix. My code attempt is listed. When I upload and run the display switches between the numerals. What I want to do is display a single numeral selected by the “if” statement. Any help and suggestions will be welcomed.

#include <LedControl.h>

LedControl lc=LedControl(12,11,10,1);

int x = 1;

void setup(){
lc.shutdown(0,false); // power-saving mode on startup
lc.setIntensity(0,15); // Set the brightness to maximum value
lc.clearDisplay(0); // and clear the display
}
void Display() {
/* here is the data for the characters */
byte zero[8]= {0x00,0x18,0x24,0x24,0x24,0x24,0x18,0x00};
byte one[8]= {0x00,0x30,0x10,0x10,0x10,0x10,0x38,0x00};

if (x = 0);

{for (int n = 0; n < 8; n++){lc.setRow(0,n,zero[n]);}
delay(2000);}

if (x = 1)

{for (int n = 0; n < 8; n++){lc.setRow(0,n,one[n]);}
delay(2000);}

}
void loop(){
Display();
delay(2000);

}

`````` if (x = 0);
``````

Two problems right there

``````if (x = 1)
``````

Only one there

Please remember to use code tags when posting code.

placed ; after second if statement, still switches between 0 and 1. ?

placed ; after second if statement

Why?

garysat:
placed ; after second if statement, still switches between 0 and 1. ?

Now you have two problems at each if statement.

Please use code tags and use auto formatting (Ctrl-T) in IDE for better formatting and much easier to read code.

I tried, using control T, below is the result. All I am trying to do is if x = 1 I want to display only the numeral 1, I do not want to display a zero, delay, then the numeral 1. I know for experienced programmers this is not a problem but for me it is. The code below displays first the numeral 0 then after the delay it displays the numeral 1, and keeps repeating the sequence. I would like for it to display the 1 and keep it on the display.

#include <LedControl.h>

LedControl lc=LedControl(12,11,10,1);

int x = 1;

void setup(){
lc.shutdown(0,false); // power-saving mode on startup
lc.setIntensity(0,15); // Set the brightness to maximum value
lc.clearDisplay(0); // and clear the display
}
void Display() {
/* here is the data for the characters */
byte zero[8]= {
0x00,0x18,0x24,0x24,0x24,0x24,0x18,0x00 };
byte one[8]= {
0x00,0x30,0x10,0x10,0x10,0x10,0x38,0x00 };

if (x=0);
{
for (int n = 0; n < 8; n++){
lc.setRow(0,n,zero[n]);
}
delay(2000);
}

if (x=1);
{
for (int n = 0; n < 8; n++){
lc.setRow(0,n,one[n]);
}
delay(2000);
}

}
void loop(){
Display();
delay(2000);

}

``````  if (x=0);
``````

You clearly are not listening. If statements do not end with ;. The equality operator is ==, not =.

thanks, finally got it thru this dense brain.