led matrix 5X7, help improve code

It is a simple led matrix, made by me, which are piranha LEDs connected to 1 column (+) and 1 row (-)

It is similar to the led matrix below.

I pass it over here, to see if someone can help me reduce the code I did … which basically makes the LED, a LED runs from left to right in the first row, when this ends up in the second row the led Walk from right to left.
and changing consecutively, leaving the even rows that the led goes from left to right and the odd rows that the led goes from right to left.

code:

int row = {A0,13,12,11,10,9,8,7}; //rows
int columns = {6,5,4,3,2}; //columns
int tiempo = 600;

void setup () {
for(int f=0;f<=7;f++) {
pinMode(row[f] , OUTPUT);
digitalWrite(row[f],HIGH); }

for(int c=0;c<=4;c++) {
pinMode(columns

 , OUTPUT);
  digitalWrite(columns[c],LOW); } 
}

void loop() {
 
 digitalWrite(row[0],LOW);
 for(int x=0;x<=4;x++) {
 digitalWrite(columns[x],HIGH);
 delay (tiempo);
 digitalWrite(columns[x],LOW);;}
 digitalWrite(row[0],HIGH);
  
  digitalWrite(row[1],LOW);
  for(int x=4;x>=0;x--) {
  digitalWrite(columns[x],HIGH);
  delay (tiempo);
  digitalWrite(columns[x],LOW);}
  digitalWrite(row[1],HIGH);

 digitalWrite(row[2],LOW);
 for(int x=0;x<=4;x++) {
 digitalWrite(columns[x],HIGH);
 delay (tiempo);
 digitalWrite(columns[x],LOW);}
 digitalWrite(row[2],HIGH);

  digitalWrite(row[3],LOW);
  for(int x=4;x>=0;x--) {
  digitalWrite(columns[x],HIGH);
  delay (tiempo);
  digitalWrite(columns[x],LOW);}
  digitalWrite(row[3],HIGH);
  
 digitalWrite(row[4],LOW);
 for(int x=0;x<=4;x++) {
 digitalWrite(columns[x],HIGH);
 delay (tiempo);
 digitalWrite(columns[x],LOW);}
 digitalWrite(row[4],HIGH);

  digitalWrite(row[5],LOW);
  for(int x=4;x>=0;x--) {
  digitalWrite(columns[x],HIGH);
  delay (tiempo);
  digitalWrite(columns[x],LOW);}
  digitalWrite(row[5],HIGH);

 digitalWrite(row[6],LOW);
 for(int x=0;x<=4;x++) {
 digitalWrite(columns[x],HIGH);
 delay (tiempo);
 digitalWrite(columns[x],LOW);}
 digitalWrite(row[6],HIGH);

  digitalWrite(row[7],LOW);
  for(int x=4;x>=0;x--) {
  digitalWrite(columns[x],HIGH);
  delay (tiempo);
  digitalWrite(columns[x],LOW);}
  digitalWrite(row[7],HIGH);
  }

You did not read this before posting a programming question

Look at your code in the original post then read the above thread and post the code again using code tags

when dealing with matrixes if you think in terms of 2D coordinates you can do almost any pattern with a little math. to do this sort of math you generally need a loop inside a loop to create movement in 2d space.

here is how you can calculate the movement you described.
run this loop and you will see what i’m talking about

 int x=0; int y=0; int dir=1;
  while(y<5){
  while(x>-1&&x<7){
    Serial.println("turn light on at: "+String(x)+","+String(y));
    delay(500);
    x+=dir;}
    dir*=-1;x+=dir; y++;}

once you understand the concept… to answer the second part of your question you can save the places you have been in a 2D array. 2D arrays can be used as a “Grid” to represent data for a 2D matrix.

the math to figure a checker board pattern you simply add the row number to the colum then check if it is an even number. (to check and even number you see if the remainder is 0 when devided by2). then light it up if you have been there!
here is another scetch that shows off the entire math for everything you mentioned. luckily i was bored tonight. LOL

 bool save [7][5];
void setup() {

 Serial.begin(9600);
 int x=0; int y=0; int dir=1;
  while(y<5){
  while(x>-1&&x<7){
    if((x+y)%2==0){  save[x][y] = true;}
    show(x,y);
    delay(500);
    x+=dir;}
    dir*=-1;x+=dir; y++;}
 }
 void show (int xx,int yy){
   
  int x = 0;
  int y = 0;
  while(y<5){x=0;
      while(x<7){
        bool on = false;
        if(save[x][y]){on = true;}
        if(xx==x&yy==y){on=true;} 
        if(on){ 
          // turns on x and y coordinates
          Serial.print("X ");}else{
          // turns off x and y coordinates
            Serial.print("- ");}
    x++;} Serial.println("");
  y++;}Serial.println("");}


 
void loop() {
}