2 8x8 led matrix no extra hardware

okay i have hooked up to 8x8 matrix directly to my arduino mega. I have identified which pin connects to what row and column since i couldnt find a schematic online, so now as you can see below it takes ALOT of code just to make them blink, i have been trying to understand how to use nested loops but quite frankly i have no other programming experience except what i have taught myself how can i simplify my code? just to clarify in my code hor stands for horizontal and ver for vertical...they are in the shape of an 8 one atop the other not next to each other.

int hor1 =  36;
int hor2 =  34;
int hor3 =  26;
int hor4 =  42;
int hor5 =  24;
int hor6 =  46;
int hor7 =  48;
int hor8 =  30;

int hor9 =  37;
int hor10 = 35;
int hor11 = 27;
int hor12 = 43;
int hor13 = 25;
int hor14 = 47;
int hor15 = 49;
int hor16 = 31;

int ver1 = 44;
int ver2 = 50;
int ver3 = 52;
int ver4 = 40;
int ver5 = 28;
int ver6 = 38;
int ver7 = 32;
int ver8 = 22;

int ver9 = 45;
int ver10 = 51;
int ver11 = 53;
int ver12 = 41;
int ver13 = 29;
int ver14 = 39;
int ver15 = 33;
int ver16 = 23;



void setup(){

  pinMode(hor1, OUTPUT);
  pinMode(hor2, OUTPUT);
  pinMode(hor3, OUTPUT);
  pinMode(hor4, OUTPUT);
  pinMode(hor5, OUTPUT);
  pinMode(hor6, OUTPUT);
  pinMode(hor7, OUTPUT);
  pinMode(hor8, OUTPUT);
  
  pinMode(hor9 , OUTPUT);
  pinMode(hor10, OUTPUT);
  pinMode(hor11, OUTPUT);
  pinMode(hor12, OUTPUT);
  pinMode(hor13, OUTPUT);
  pinMode(hor14, OUTPUT);
  pinMode(hor15, OUTPUT);
  pinMode(hor16, OUTPUT);
  

  pinMode(ver1, OUTPUT);
  pinMode(ver2, OUTPUT);
  pinMode(ver3, OUTPUT);
  pinMode(ver4, OUTPUT);
  pinMode(ver5, OUTPUT);
  pinMode(ver6, OUTPUT);
  pinMode(ver7, OUTPUT);
  pinMode(ver8, OUTPUT); 
  
  pinMode(ver9 , OUTPUT);
  pinMode(ver10, OUTPUT);
  pinMode(ver11, OUTPUT);
  pinMode(ver12, OUTPUT);
  pinMode(ver13, OUTPUT);
  pinMode(ver14, OUTPUT);
  pinMode(ver15, OUTPUT);
  pinMode(ver16, OUTPUT); 
  
}

void loop()
{

matrix1on();
delay(250);
alloff();
delay(250);
matrix2on();
delay(250);
alloff();
delay(250);
}

the functions i declared are here

void allon(){


  digitalWrite(hor1, LOW);     
  digitalWrite(hor2, LOW);     
  digitalWrite(hor3, LOW);     
  digitalWrite(hor4, LOW);    
  digitalWrite(hor5, LOW);     
  digitalWrite(hor6, LOW);   
  digitalWrite(hor7, LOW);    
  digitalWrite(hor8, LOW);

  digitalWrite(hor9 , LOW);     
  digitalWrite(hor10, LOW);     
  digitalWrite(hor11, LOW);     
  digitalWrite(hor12, LOW);    
  digitalWrite(hor13, LOW);     
  digitalWrite(hor14, LOW);   
  digitalWrite(hor15, LOW);    
  digitalWrite(hor16, LOW);


  digitalWrite(ver1, HIGH);
  digitalWrite(ver2, HIGH);
  digitalWrite(ver3, HIGH);
  digitalWrite(ver4, HIGH);
  digitalWrite(ver5, HIGH); 
  digitalWrite(ver6, HIGH);
  digitalWrite(ver7, HIGH); 
  digitalWrite(ver8, HIGH);

  digitalWrite(ver9, HIGH);
  digitalWrite(ver10, HIGH);
  digitalWrite(ver11, HIGH);
  digitalWrite(ver12, HIGH);
  digitalWrite(ver13, HIGH); 
  digitalWrite(ver14, HIGH);
  digitalWrite(ver15, HIGH); 
  digitalWrite(ver16, HIGH);

}

void matrix2on(){
  digitalWrite(hor9 , LOW);     
  digitalWrite(hor10, LOW);     
  digitalWrite(hor11, LOW);     
  digitalWrite(hor12, LOW);    
  digitalWrite(hor13, LOW);     
  digitalWrite(hor14, LOW);   
  digitalWrite(hor15, LOW);    
  digitalWrite(hor16, LOW);

  digitalWrite(ver9, HIGH);
  digitalWrite(ver10, HIGH);
  digitalWrite(ver11, HIGH);
  digitalWrite(ver12, HIGH);
  digitalWrite(ver13, HIGH); 
  digitalWrite(ver14, HIGH);
  digitalWrite(ver15, HIGH); 
  digitalWrite(ver16, HIGH);

}

void matrix1on(){
  digitalWrite(hor1, LOW);     
  digitalWrite(hor2, LOW);     
  digitalWrite(hor3, LOW);     
  digitalWrite(hor4, LOW);    
  digitalWrite(hor5, LOW);     
  digitalWrite(hor6, LOW);   
  digitalWrite(hor7, LOW);    
  digitalWrite(hor8, LOW);

  digitalWrite(ver1, HIGH);
  digitalWrite(ver2, HIGH);
  digitalWrite(ver3, HIGH);
  digitalWrite(ver4, HIGH);
  digitalWrite(ver5, HIGH); 
  digitalWrite(ver6, HIGH);
  digitalWrite(ver7, HIGH); 
  digitalWrite(ver8, HIGH);
}


void alloff(){
  digitalWrite(hor1, LOW);     
  digitalWrite(hor2, LOW);     
  digitalWrite(hor3, LOW);     
  digitalWrite(hor4, LOW);    
  digitalWrite(hor5, LOW);     
  digitalWrite(hor6, LOW);   
  digitalWrite(hor7, LOW);    
  digitalWrite(hor8, LOW);

  digitalWrite(hor9 , LOW);     
  digitalWrite(hor10, LOW);     
  digitalWrite(hor11, LOW);     
  digitalWrite(hor12, LOW);    
  digitalWrite(hor13, LOW);     
  digitalWrite(hor14, LOW);   
  digitalWrite(hor15, LOW);    
  digitalWrite(hor16, LOW);


  digitalWrite(ver1, LOW);
  digitalWrite(ver2, LOW);
  digitalWrite(ver3, LOW);
  digitalWrite(ver4, LOW);
  digitalWrite(ver5, LOW); 
  digitalWrite(ver6, LOW);
  digitalWrite(ver7, LOW); 
  digitalWrite(ver8, LOW);

  digitalWrite(ver9,  LOW);
  digitalWrite(ver10, LOW);
  digitalWrite(ver11, LOW);
  digitalWrite(ver12, LOW);
  digitalWrite(ver13, LOW); 
  digitalWrite(ver14, LOW);
  digitalWrite(ver15, LOW); 
  digitalWrite(ver16, LOW);
  
}

any help would be highly appreciated! :P :P :P :P :P ;D ;D ;D

I recommend you to not use hard coding while software developing. Try to make parametric and reusable code. Eg. put pins in an array and itarate with for statement. I hope following example helps you.

int pinsHor[]={36,34,26,42,24,46,48,30,37,35,27,43,25,47,49,31};
int pinsVer[]={44,50,52,40,28,38,32,22,45,51,53,41,29,39,33,23};

void setup(){
  for (int i=0;i<16;i++) {
    pinMode(pinsHor[i], OUTPUT);
    pinMode(pinsVer[i], OUTPUT);
  }
}

void loop(){
}

what do you mean hard coding? sorry…lol but then how would i address each led individually?

If you are driving 2 8 x 8 LED matrices directly from your Arduino without any other hardware you are probably putting the life of your Arduino in great danger.

It is very easy to address single led. See the code

int pinsHor[]={36,34,26,42,24,46,48,30,37,35,27,43,25,47,49,31};
int pinsVer[]={44,50,52,40,28,38,32,22,45,51,53,41,29,39,33,23};

void setup(){
  for (int i=0;i<16;i++) {
    pinMode(pinsHor[i], OUTPUT);
    pinMode(pinsVer[i], OUTPUT);
  }
}

void loop(){
} 

void ledOn(int hor, int ver) {
  digitalWrite(pinsHor[hor], LOW);
  digitalWrite(pinsVer[ver], HIGH);
}

void ledOff(int hor, int ver) {
  digitalWrite(pinsHor[hor], LOW);
  digitalWrite(pinsVer[ver], LOW);
}

void allOn() {
   for (int i=0;i<16;i++) {
    digitalWrite(pinsHor[i], LOW);
    digitalWrite(pinsVer[i], HIGH);
  }  
}

void allOff() {
   for (int i=0;i<16;i++) {
    digitalWrite(pinsHor[i], LOW);
    digitalWrite(pinsVer[i], LOW);
  }  
}