led on in the given sequence

i want to turn led’s on in a sequence
the sequence is
** {0, 0, 0, 0, 0, 0, 0, 0},**
** {1, 0, 0, 0, 0, 0, 0, 0},**
** {0, 1, 0, 0, 0, 0, 0, 0},**
** {0, 0, 1, 0, 0, 0, 0, 0},**
** {0, 0, 0, 1, 0, 0, 0, 0},**
** {0, 0, 0, 0, 1, 0, 0, 0},**
** {0, 0, 0, 0, 0, 1, 0, 0},**
** {0, 0, 0, 0, 0, 0, 1, 0},**
** {0, 0, 0, 0, 0, 0, 0, 1},**
** {1, 1, 1, 1, 1, 1, 1, 1},**
wherever the 1 is there only the led will on.
i did a multidimesional array for this
thats given below:

void setup()
{
  // define pin modes
  for(int pin=6;pin<=13;pin++)
  {
    pinMode(pin,OUTPUT);
     
  }
}
  int digit[10][8]={ 
     {0, 0, 0, 0, 0, 0, 0, 0}, 
     {1, 0, 0, 0, 0, 0, 0, 0},
     {0, 1, 0, 0, 0, 0, 0, 0},
     {0, 0, 1, 0, 0, 0, 0, 0},
     {0, 0, 0, 1, 0, 0, 0, 0},
     {0, 0, 0, 0, 1, 0, 0, 0},
     {0, 0, 0, 0, 0, 1, 0, 0},
     {0, 0, 0, 0, 0, 0, 1, 0},
     {0, 0, 0, 0, 0, 0, 0, 1},
     {1, 1, 1, 1, 1, 1, 1, 1},
 
};

void loop() 
{
  
for(int num=0;num<=10;num++){

   for(int count=0;count<=8;count++){

    digitalWrite(count+6,digit[num][count]);
   }
 
 
delay(2000);
}
}


i want some different way to do that code
how i can do that?

digitalWrite( 6, 0 );
digitalWrite( 7, 0 );
digitalWrite( 8, 0 );
digitalWrite( 9, 0 );
digitalWrite( 10, 0 );
digitalWrite( 11, 0 );
digitalWrite( 12, 0 );
digitalWrite( 13, 0 );
digitalWrite( 6, 1 );
digitalWrite( 7, 0 );
digitalWrite( 8, 0 );
digitalWrite( 9, 0 );
digitalWrite( 10, 0 );
digitalWrite( 11, 0 );
digitalWrite( 12, 0 );
digitalWrite( 13, 0 );
digitalWrite( 6, 0 );
digitalWrite( 7, 1 );
digitalWrite( 8, 0 );
digitalWrite( 9, 0 );
digitalWrite( 10, 0 );
digitalWrite( 11, 0 );
digitalWrite( 12, 0 );
digitalWrite( 13, 0 );
digitalWrite( 6, 0 );
digitalWrite( 7, 0 );
digitalWrite( 8, 1 );
digitalWrite( 9, 0 );
digitalWrite( 10, 0 );
digitalWrite( 11, 0 );
digitalWrite( 12, 0 );
digitalWrite( 13, 0 );
digitalWrite( 6, 0 );
digitalWrite( 7, 0 );
digitalWrite( 8, 0 );
digitalWrite( 9, 1 );
digitalWrite( 10, 0 );
digitalWrite( 11, 0 );
digitalWrite( 12, 0 );
digitalWrite( 13, 0 );
digitalWrite( 6, 0 );
digitalWrite( 7, 0 );
digitalWrite( 8, 0 );
digitalWrite( 9, 0 );
digitalWrite( 10, 1 );
digitalWrite( 11, 0 );
digitalWrite( 12, 0 );
digitalWrite( 13, 0 );
digitalWrite( 6, 0 );
digitalWrite( 7, 0 );
digitalWrite( 8, 0 );
digitalWrite( 9, 0 );
digitalWrite( 10, 0 );
digitalWrite( 11, 1 );
digitalWrite( 12, 0 );
digitalWrite( 13, 0 );
digitalWrite( 6, 0 );
digitalWrite( 7, 0 );
digitalWrite( 8, 0 );
digitalWrite( 9, 0 );
digitalWrite( 10, 0 );
digitalWrite( 11, 0 );
digitalWrite( 12, 1 );
digitalWrite( 13, 0 );
digitalWrite( 6, 0 );
digitalWrite( 7, 0 );
digitalWrite( 8, 0 );
digitalWrite( 9, 0 );
digitalWrite( 10, 0 );
digitalWrite( 11, 0 );
digitalWrite( 12, 0 );
digitalWrite( 13, 1 );
digitalWrite( 6, 1 );
digitalWrite( 7, 1 );
digitalWrite( 8, 1 );
digitalWrite( 9, 1 );
digitalWrite( 10, 1 );
digitalWrite( 11, 1 );
digitalWrite( 12, 1 );
digitalWrite( 13, 1 );

Your first code has 2 bugs (in the upper limit of your 2 for loops versus your array' sizes)

Given you have 8 LEDs you could just use a byte to represent that status and the bitRead macro to check if the bit is 0 or 1. You array would be

byte digit = { 
     B00000000,
     B10000000,
     B01000000,
     B00100000,
   ... you get the idea
     B11111111
};

@J-M-L

i understand a little but please write a full code for that program then i can understand well

We are not here to do your homework. Try something and if it's buggy I'll tell you.

  int digit[10][8]={
     {0, 0, 0, 0, 0, 0, 0, 0},
     {1, 0, 0, 0, 0, 0, 0, 0},
     {0, 1, 0, 0, 0, 0, 0, 0},
     {0, 0, 1, 0, 0, 0, 0, 0},
     {0, 0, 0, 1, 0, 0, 0, 0},
     {0, 0, 0, 0, 1, 0, 0, 0},
     {0, 0, 0, 0, 0, 1, 0, 0},
     {0, 0, 0, 0, 0, 0, 1, 0},
     {0, 0, 0, 0, 0, 0, 0, 1},
     {1, 1, 1, 1, 1, 1, 1, 1},
};

Are you sure that you don't need to use long or long long to hold those values?

i dont know thats why i asked here :frowning:

"please write a full code for that program then i can understand well"

Really!

.

Why do you need all 1's

.

“i want some different way to do that code”
You can use Direct Port Manipulation and the small array that J-M-L showed.
7-6 are on Port D, 13-8 are on Port B (on an Uno or other '328P based chip.
Loop thru the array and send the data to the 2 ports.

for (x=0; x<10; x=x+1){ // loop thru the array
PORTB = (digit[x]>>2); // shift data into position and write the data to the port, bits 6/7 are not accessible.
PORTD = PORTD & 0b00111111;  // clear upper two bits, leave the rest alone
PORTD = PORTD | (digit[x]<<6); // shift the data into position and OR the upper 2 bits into the register
delay(1000); // pause so you can see the result
}

how to easily solve this problem?? that everyone can understand????

If you want very simple, Everyone will understand answer #1 :slight_smile:
(Which should be cleaned up a bit using HIGH and LOW and no need to set LOW a pin that’s already LOW)

@J-M-L
dont i need to write anything else in #1 code????

a little bit confused,as i am beginner