Programming problem- no error messages. passing arrays in a function.

I am fairly new to programming so I have most definitely done something wrong.

My program is meant to check when a switch is pressed and then depending on which switch is pressed it will then display a particular sequence. However I have not included the other switches or the sequences as I just want to check the program works for just the one switch and display the corresponding sequence.

The program compiles and loads fine but doesnt display the sequence, which leads me to believe that I have made a programming error. This error, may lie in the function I am trying to pass. There are no problems with the circuit as I have tested it with ‘example’ files.

Thank you for your time to read this, if you have any questions please ask.
Andy

#include <stdlib.h>
#include <stdio.h>

// constants won't change. They're used here to set pin numbers:

const int switch2 = 2; // the number of the pushbutton pin


int ledPins[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13};
int pinCount = 14;

   void setup() {
    // initialize the LED pin as an output:
    for (int thisPin = 7; thisPin < pinCount;) {
    pinMode(ledPins[thisPin], OUTPUT);
    // initialize the switch pin as an input:
    
 }
} 
//when switch 2 is pressed this is the sequence for the leds:
   int array2[15][8] = {{1,0,0,0,0,0,0,0},
                        {1,1,1,0,0,0,0,0},
                        {1,1,1,1,0,0,0,0},
                        {1,1,1,1,1,0,0,0},
                        {1,1,1,1,1,1,0,0},
                        {1,1,1,1,1,1,1,0},
                        {1,1,1,1,1,1,1,1},
                        {1,1,1,1,1,1,1,0},
                        {1,1,1,1,1,1,0,0},
                        {1,1,1,1,1,0,0,0},
                        {1,1,1,1,0,0,0,0},
                        {1,1,1,0,0,0,0,0},
                        {1,1,0,0,0,0,0,0},
                        {1,0,0,0,0,0,0,0},
                        {0,0,0,0,0,0,0,0}};



void switch2a(int array2[15][8], int MAX_ROW, int repeat)
{
    int row_count = 0;
    int end_of_column = 7;
    int thisPin = 7;
    
    for (int repeat_count = 0; repeat_count < repeat;)
        for (int column_number = 0; column_number < 8; column_number++) {
            // if the number in the matrix is equal to 1 then the led will turn on
            if (array2[row_count][column_number] == 1) {
                
            
                
                // turn LED on:
                digitalWrite(ledPins[thisPin], HIGH);
               
            
            }
            else {
                // turn LED off:
                digitalWrite(ledPins[thisPin], LOW);
                
            }
            
        
            //this checks if it is at the end of the se
            if (column_number == end_of_column) {
                column_number = 0;
                row_count++;
            }
            
            if (row_count == MAX_ROW) {
                row_count = 0;
                repeat_count++;
            }
            
            //end of led pin, so restart back to the begining
            if (thisPin == 13) {
                thisPin = 7;
            }

        }
}
   
// the variables that will change:
int switchState2 = 0;  // variable for reading the switch status


void loop()
{ 
  switch2a(array2,15,10);
}
    for (int thisPin = 7; thisPin < pinCount;) {
    pinMode(ledPins[thisPin], OUTPUT);

Since there is no increment portion for the for loop, thisPin will never have a value of other than 7. Therefore, this loop will never end.

Array indexes start at 0, not 7.

I knew I had done something stupid. Thanks a lot!
With regards to the array index, I did want it to start at 7, its the way LED's are connected to the pins.
Thanks again.

I did want it to start at 7, its the way LED’s are connected to the pins.

Why? The only numbers that should be in the array are the numbers of the pins that are to be used:

int ledPins[] = {8,9,10,11,12,13};

Then fix the count, and start at 0.

That makes sense. Thanks again for your help

You’ll probably ignore the following as too complicated but to do so would be a mistake as there are some very useful things to learn within it.

I’m hoping you’ll look it over and ask questions concerning thing you’re not familiar with.

It is completely untested and may not work with your setup, then again it might also work just fine.

#define ARRAY_ENTRIES(ARRAY)        (sizeof(ARRAY) / sizeof(ARRAY[0]))

const uint8_t   pinSWITCH   = 2;

const uint8_t   pinLED_0    =  7;       // CHANGE PIN NUMBER HERE, NOTHING ELSE NEEDS CHANGE
const uint8_t   pinLED_1    =  8;       // CHANGE PIN NUMBER HERE, NOTHING ELSE NEEDS CHANGE
const uint8_t   pinLED_2    =  9;       // CHANGE PIN NUMBER HERE, NOTHING ELSE NEEDS CHANGE
const uint8_t   pinLED_3    = 10;       // CHANGE PIN NUMBER HERE, NOTHING ELSE NEEDS CHANGE
const uint8_t   pinLED_4    = 11;       // CHANGE PIN NUMBER HERE, NOTHING ELSE NEEDS CHANGE
const uint8_t   pinLED_5    = 12;       // CHANGE PIN NUMBER HERE, NOTHING ELSE NEEDS CHANGE
const uint8_t   pinLED_6    = 13;       // CHANGE PIN NUMBER HERE, NOTHING ELSE NEEDS CHANGE
const uint8_t   pinLED_7    = 14;       // CHANGE PIN NUMBER HERE, NOTHING ELSE NEEDS CHANGE

const uint8_t   LED_OFF     = LOW;      // YOU MAY WANT TO SWAP THE VALUE OF THIS WITH 'LED_ON'
const uint8_t   LED_ON      = HIGH;     // YOU MAY WANT TO SWAP THE VALUE OF THIS WITH 'LED_OFF'

const uint8_t   SWITCH_OFF  = LOW;      // YOU MAY WANT TO SWAP THE VALUE OF THIS WITH 'SWITCH_ON'
const uint8_t   SWITCH_ON   = HIGH;     // YOU MAY WANT TO SWAP THE VALUE OF THIS WITH 'SWITCH_OFF'

const uint8_t pinsLEDS[]        =
{
    pinLED_0, pinLED_1, pinLED_2, pinLED_3, pinLED_4, pinLED_5, pinLED_6, pinLED_7
};

//when switch 2 is pressed this is the sequence for the leds:
const uint8_t array2[] =
{
      0b10000000    //  0
    , 0b11100000    //  1
    , 0b11110000    //  2
    , 0b11111000    //  3
    , 0b11111100    //  4
    , 0b11111110    //  5
    , 0b11111111    //  6
    , 0b11111110    //  7
    , 0b11111100    //  8
    , 0b11111000    //  9
    , 0b11110000    // 10
    , 0b11100000    // 11
    , 0b11000000    // 12
    , 0b10000000    // 13
    , 0b00000000    // 14
};


void sequence(const uint8_t array[], size_t entries, int repeat)
{
    for ( int repeat_count = repeat; repeat--; )
    {
        for ( size_t i = 0; i < entries; i++ )
        {
            for ( int mask = 0b10000000; mask;  mask >>= 1 )
            {
                digitalWrite(array[i], ((array[i] & mask) ? LED_ON : LED_OFF));
            }
        }
    }
}


void loop()
{
    sequence(array2, ARRAY_ENTRIES(array2), 10);
}


void setup()
{
    pinMode(pinSWITCH, INPUT);
    
    for ( size_t i = ARRAY_ENTRIES(pinsLEDS); i--; )
    {
        pinMode(pinsLEDS[i], OUTPUT);
    }
}
const int pinsLEDS[]

Why not uint8_t, like its contents?

Good question, good catch.

I find I sometimes hit 'undo' one to many times when editing or refactoring code and sometime don't catch the issue before posting - this is one such case.

AWOL:

const int pinsLEDS[]

Why not uint8_t, like its contents?

Sorry I dont really understand what you are saying. what is uint8_t?

what is uint8_t?

The datatype you used here:const uint8_t  pinLED_0    =  7;

Oh ok, Thanks again I am very grateful

Andy, Did You finally get the project working?
If you did I was wondering if you could share the finished projects code.
I am trying to do a scrolling message center with an 8x8 led matrix, the center would have 7 pre-difined messages and depending on the switch selected that would determine the message that would be scrolled across the matrix.
Thanks

Yeah I kind of have it finished apart from the bit I’ve commented out at near the bottom. I have made a post for this as I cant work it out called logic problem. Maybe you know what the problem is…?

The program is lengthy and by no means the best way of doing but maybe it’ll help. I will post it in chunks as I’m limited on characters in sending messages.

// edit version of program


// constants won't change. They're used here to set pin numbers:

const int switch2pin = 2; // the number of the pushbutton pin
const int switch3pin = 3;
const int switch4pin = 4;
const int switch5pin = 5;

int time = 10;

int ledPins[] = {6,7,8,9,10,11,12,13};
int pinCount = 8;

   void setup() {
    // initialize the LED pin as an output:
    for (int column_number = 0; column_number < pinCount; column_number++) {
    pinMode(ledPins[column_number], OUTPUT);
    // initialize the switch pin as an input:
    pinMode(switch2pin, INPUT);
    pinMode(switch3pin, INPUT);
    pinMode(switch4pin, INPUT);
    pinMode(switch5pin, INPUT);
    Serial.begin(9600);
 } 
} 


 
                      
   int array2[16][8] = {{1,0,0,0,0,0,0,0},
                        {1,1,0,0,0,0,0,0},
                        {1,1,1,0,0,0,0,0},
                        {1,1,1,1,0,0,0,0},
                        {1,1,1,1,1,0,0,0},
                        {1,1,1,1,1,1,0,0},
                        {1,1,1,1,1,1,1,0},
                        {1,1,1,1,1,1,1,1},
                        {1,1,1,1,1,1,1,0},
                        {1,1,1,1,1,1,0,0},
                        {1,1,1,1,1,0,0,0},
                        {1,1,1,1,0,0,0,0},
                        {1,1,1,0,0,0,0,0},
                        {1,1,0,0,0,0,0,0},
                        {1,0,0,0,0,0,0,0},
                        {0,0,0,0,0,0,0,0}};
                        
  int array3[7][8] = {{1,0,0,0,0,0,0,1},
                      {0,1,0,0,0,0,1,0},
                      {0,0,1,0,0,1,0,0},
                      {0,0,0,1,1,0,0,0},
                      {0,0,1,0,0,1,0,0},
                      {0,1,0,0,0,0,1,0},
                      {1,0,0,0,0,0,0,1}};
                      
  int array4[15][8] = {{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},
                       {0,0,0,0,0,0,1,0},
                       {0,0,0,0,0,1,0,0},
                       {0,0,0,0,1,0,0,0},
                       {0,0,0,1,0,0,0,0},
                       {0,0,1,0,0,0,0,0},
                       {0,1,0,0,0,0,0,0},
                       {1,0,0,0,0,0,0,0}};
                       
                       
  int array5[2][8] = {{1,1,1,1,0,0,0,0},
                      {0,0,0,0,1,1,1,1}};
                    
  int array6[3][8] = {{0,1,1,0,0,0,0,0},
                      {0,0,1,0,0,0,0,0},
                      {0,0,0,0,0,0,0,0}};
                      
 
 void switch2a(int array2[16][8], int MAX_ROW, int repeat)
{
    int row_count = 0;
    int end_of_column = 7;
    int repeat_count = 0;
    
    
        for (int column_number = 0; column_number < 8; column_number++) {
          if (repeat_count < repeat) {
            
            // if the number in the matrix is equal to 1 then the led will turn on
            if (array2[row_count][column_number] == 1) 
            {
                
           
                
    // turn LED on:
        digitalWrite(ledPins[column_number], HIGH);
        delay(time);
        
             
            }
            
            else {
                // turn LED off:
                digitalWrite(ledPins[column_number], LOW);
                delay(time);
                
            }
             
        
            //this checks if it is at the end of the sequence
            if (column_number == end_of_column) {
                column_number = -1;
                 
                row_count++;
            }
            
            if (row_count == MAX_ROW) {
                row_count = 0;
                repeat--;
            }
        }
}
}
  
  
   void switch3a(int array3[7][8], int MAX_ROW, int repeat)
{
    int row_count = 0;
    int end_of_column = 7;
    int repeat_count = 0;
    
   
        for (int column_number = 0; column_number < 8; column_number++) {
          if (repeat_count < repeat) {
            // if the number in the matrix is equal to 1 then the led will turn on
            if (array3[row_count][column_number] == 1) 
            {
                
            
                
    // turn LED on:
        digitalWrite(ledPins[column_number], HIGH);
        delay(time);
        
             
            }
            
            else {
                // turn LED off:
                digitalWrite(ledPins[column_number], LOW);
                delay(time);
                
            }
             
        
            //this checks if it is at the end of the sequence
            if (column_number == end_of_column) {
                column_number = -1;
                row_count++;
            }
            
            if (row_count == MAX_ROW) {
                row_count = 0;
                repeat--;
            }
        }
}
}

second part…

 void switch4a(int array4[15][8], int MAX_ROW, int repeat)
{
    int row_count = 0;
    int end_of_column = 7;
    int repeat_count = 0;
    
    
        for (int column_number = 0; column_number < 8; column_number++) {
          if (repeat_count < repeat) {
            // if the number in the matrix is equal to 1 then the led will turn on
            if (array4[row_count][column_number] == 1) 
            {
                
            
                
    // turn LED on:
        digitalWrite(ledPins[column_number], HIGH);
        delay(time);
        
             
            }
            
            else {
                // turn LED off:
                digitalWrite(ledPins[column_number], LOW);
                delay(time);
                
            }
             
        
            //this checks if it is at the end of the sequence
            if (column_number == end_of_column) {
                column_number = -1;
                row_count++;
            }
            
            if (row_count == MAX_ROW) {
                row_count = 0;
                repeat--;
            }
        }
      }
}

  
 void  switch_not_pressed(int array6[3][8], int MAX_ROW, int repeat)
{
    int row_count = 0;
    int end_of_column = 7;
    int repeat_count = 0;
    
    
        for (int column_number = 0; column_number < 8; column_number++) {
          if (repeat_count < repeat) {
            
            // if the number in the matrix is equal to 1 then the led will turn on
            if (array6[row_count][column_number] == 1) 
            {
                
            
                
    // turn LED on:
        digitalWrite(ledPins[column_number], HIGH);
        delay(time);
        
             
            }
            
            else {
                // turn LED off:
                digitalWrite(ledPins[column_number], LOW);
                delay(time);
                
            }
             
        
            //this checks if it is at the end of the sequence
            if (column_number == end_of_column) {
                column_number = -1;
                row_count++;
            }
            
            if (row_count == MAX_ROW) {
                row_count = 0;
                repeat--;
            }
    }    
}
} 

 void  multiple_switches(int array5[2][8], int MAX_ROW, int repeat)
{
    int row_count = 0;
    int end_of_column = 7;
    int repeat_count = 0;
    
    
        for (int column_number = 0; column_number < 8; column_number++) {
          if (repeat_count < repeat) {
            
            // if the number in the matrix is equal to 1 then the led will turn on
            if (array5[row_count][column_number] == 1) 
            {
                
            
                
    // turn LED on:
        digitalWrite(ledPins[column_number], HIGH);
        delay(20);
        
             
            }
            
            else {
                // turn LED off:
                digitalWrite(ledPins[column_number], LOW);
                delay(20);
                
            }
             
        
            //this checks if it is at the end of the sequence
            if (column_number == end_of_column) {
                column_number = -1;
                row_count++;
            }
            
            if (row_count == MAX_ROW) {
                row_count = 0;
                repeat--;
            }
    }    
}
} 



void loop()
{ 
  // the variables that will change:
int switchState2 = 0;  // variable for reading the switch status
int switchState3 = 0;
int switchState4 = 0;
int switchState5 = 0;

  switchState2 = digitalRead(switch2pin);
  switchState3 = digitalRead(switch3pin);
  switchState4 = digitalRead(switch4pin);
  switchState5 = digitalRead(switch5pin);
  
 
   
 
  if ((switchState2 || switchState3 || switchState4 || switchState5) == 0) {
    
   switch_not_pressed(array6,3,1);
  }

   
   
  /*THIS DOESNT WORK!!!
 
  if ( ((switchState2 && switchState3) || (switchState2 && switchState4) || (switchState2 && switchState5) 
         || (switchState3 && switchState4) || (switchState3 && switchState5) || (switchState4 && switchState5))  == 1) {
         
         multiple_switches(array5,2,1);
       }
         
   */
       
  

    if (switchState2 == 1) { 
      switch2a(array2,16,10);
    }
    
    if (switchState3 == 1) {
      switch3a(array3,7,10);
    }
    if (switchState4 == 1) {
      switch4a(array4,15,10);
    }
    if (switchState5 == 1) {
      switch2a(array2,16,10);
      switch3a(array3,7,10);
      switch4a(array4,15,10);
    }  
}

Please use the IDE's auto format feature and repost.
My eyes hurt.

// edit version of program


// constants won't change. They're used here to set pin numbers:

const int switch2pin = 2; // the number of the pushbutton pin
const int switch3pin = 3;
const int switch4pin = 4;
const int switch5pin = 5;

int time = 10;

int ledPins[] = {
  6,7,8,9,10,11,12,13};
int pinCount = 8;

void setup() {
  // initialize the LED pin as an output:
  for (int column_number = 0; column_number < pinCount; column_number++) {
    pinMode(ledPins[column_number], OUTPUT);
    // initialize the switch pin as an input:
    pinMode(switch2pin, INPUT);
    pinMode(switch3pin, INPUT);
    pinMode(switch4pin, INPUT);
    pinMode(switch5pin, INPUT);
    Serial.begin(9600);
  } 
} 




int array2[16][8] = {
  {
    1,0,0,0,0,0,0,0  }
  ,
  {
    1,1,0,0,0,0,0,0  }
  ,
  {
    1,1,1,0,0,0,0,0  }
  ,
  {
    1,1,1,1,0,0,0,0  }
  ,
  {
    1,1,1,1,1,0,0,0  }
  ,
  {
    1,1,1,1,1,1,0,0  }
  ,
  {
    1,1,1,1,1,1,1,0  }
  ,
  {
    1,1,1,1,1,1,1,1  }
  ,
  {
    1,1,1,1,1,1,1,0  }
  ,
  {
    1,1,1,1,1,1,0,0  }
  ,
  {
    1,1,1,1,1,0,0,0  }
  ,
  {
    1,1,1,1,0,0,0,0  }
  ,
  {
    1,1,1,0,0,0,0,0  }
  ,
  {
    1,1,0,0,0,0,0,0  }
  ,
  {
    1,0,0,0,0,0,0,0  }
  ,
  {
    0,0,0,0,0,0,0,0  }
};

int array3[7][8] = {
  {
    1,0,0,0,0,0,0,1  }
  ,
  {
    0,1,0,0,0,0,1,0  }
  ,
  {
    0,0,1,0,0,1,0,0  }
  ,
  {
    0,0,0,1,1,0,0,0  }
  ,
  {
    0,0,1,0,0,1,0,0  }
  ,
  {
    0,1,0,0,0,0,1,0  }
  ,
  {
    1,0,0,0,0,0,0,1  }
};

int array4[15][8] = {
  {
    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  }
  ,
  {
    0,0,0,0,0,0,1,0  }
  ,
  {
    0,0,0,0,0,1,0,0  }
  ,
  {
    0,0,0,0,1,0,0,0  }
  ,
  {
    0,0,0,1,0,0,0,0  }
  ,
  {
    0,0,1,0,0,0,0,0  }
  ,
  {
    0,1,0,0,0,0,0,0  }
  ,
  {
    1,0,0,0,0,0,0,0  }
};


int array5[2][8] = {
  {
    1,1,1,1,0,0,0,0  }
  ,
  {
    0,0,0,0,1,1,1,1  }
};

int array6[3][8] = {
  {
    0,1,1,0,0,0,0,0  }
  ,
  {
    0,0,1,0,0,0,0,0  }
  ,
  {
    0,0,0,0,0,0,0,0  }
};


void switch2a(int array2[16][8], int MAX_ROW, int repeat)
{
  int row_count = 0;
  int end_of_column = 7;
  int repeat_count = 0;


  for (int column_number = 0; column_number < 8; column_number++) {
    if (repeat_count < repeat) {

      // if the number in the matrix is equal to 1 then the led will turn on
      if (array2[row_count][column_number] == 1) 
      {



        // turn LED on:
        digitalWrite(ledPins[column_number], HIGH);
        delay(time);


      }

      else {
        // turn LED off:
        digitalWrite(ledPins[column_number], LOW);
        delay(time);

      }


      //this checks if it is at the end of the sequence
      if (column_number == end_of_column) {
        column_number = -1;

        row_count++;
      }

      if (row_count == MAX_ROW) {
        row_count = 0;
        repeat--;
      }
    }
  }
}


void switch3a(int array3[7][8], int MAX_ROW, int repeat)
{
  int row_count = 0;
  int end_of_column = 7;
  int repeat_count = 0;


  for (int column_number = 0; column_number < 8; column_number++) {
    if (repeat_count < repeat) {
      // if the number in the matrix is equal to 1 then the led will turn on
      if (array3[row_count][column_number] == 1) 
      {



        // turn LED on:
        digitalWrite(ledPins[column_number], HIGH);
        delay(time);


      }

      else {
        // turn LED off:
        digitalWrite(ledPins[column_number], LOW);
        delay(time);

      }


      //this checks if it is at the end of the sequence
      if (column_number == end_of_column) {
        column_number = -1;
        row_count++;
      }

      if (row_count == MAX_ROW) {
        row_count = 0;
        repeat--;
      }
    }
  }
}

void switch4a(int array4[15][8], int MAX_ROW, int repeat)
{
  int row_count = 0;
  int end_of_column = 7;
  int repeat_count = 0;


  for (int column_number = 0; column_number < 8; column_number++) {
    if (repeat_count < repeat) {
      // if the number in the matrix is equal to 1 then the led will turn on
      if (array4[row_count][column_number] == 1) 
      {



        // turn LED on:
        digitalWrite(ledPins[column_number], HIGH);
        delay(time);


      }

      else {
        // turn LED off:
        digitalWrite(ledPins[column_number], LOW);
        delay(time);

      }


      //this checks if it is at the end of the sequence
      if (column_number == end_of_column) {
        column_number = -1;
        row_count++;
      }

      if (row_count == MAX_ROW) {
        row_count = 0;
        repeat--;
      }
    }
  }
}


void  switch_not_pressed(int array6[3][8], int MAX_ROW, int repeat)
{
  int row_count = 0;
  int end_of_column = 7;
  int repeat_count = 0;


  for (int column_number = 0; column_number < 8; column_number++) {
    if (repeat_count < repeat) {

      // if the number in the matrix is equal to 1 then the led will turn on
      if (array6[row_count][column_number] == 1) 
      {



        // turn LED on:
        digitalWrite(ledPins[column_number], HIGH);
        delay(time);


      }

      else {
        // turn LED off:
        digitalWrite(ledPins[column_number], LOW);
        delay(time);

      }


      //this checks if it is at the end of the sequence
      if (column_number == end_of_column) {
        column_number = -1;
        row_count++;
      }

      if (row_count == MAX_ROW) {
        row_count = 0;
        repeat--;
      }
    }    
  }
} 

void  multiple_switches(int array5[2][8], int MAX_ROW, int repeat)
{
  int row_count = 0;
  int end_of_column = 7;
  int repeat_count = 0;


  for (int column_number = 0; column_number < 8; column_number++) {
    if (repeat_count < repeat) {

      // if the number in the matrix is equal to 1 then the led will turn on
      if (array5[row_count][column_number] == 1) 
      {



        // turn LED on:
        digitalWrite(ledPins[column_number], HIGH);
        delay(20);


      }

      else {
        // turn LED off:
        digitalWrite(ledPins[column_number], LOW);
        delay(20);

      }


      //this checks if it is at the end of the sequence
      if (column_number == end_of_column) {
        column_number = -1;
        row_count++;
      }

      if (row_count == MAX_ROW) {
        row_count = 0;
        repeat--;
      }
    }    
  }
} 



void loop()
{ 
  // the variables that will change:
  int switchState2 = 0;  // variable for reading the switch status
  int switchState3 = 0;
  int switchState4 = 0;
  int switchState5 = 0;

  switchState2 = digitalRead(switch2pin);
  switchState3 = digitalRead(switch3pin);
  switchState4 = digitalRead(switch4pin);
  switchState5 = digitalRead(switch5pin);








  /*
 
   if ( ((switchState2 && switchState3 == 1) || 
   (switchState2 && switchState4 == 1) || 
   (switchState2 && switchState5 == 1) || 
   (switchState3 && switchState4 == 1) || 
   (switchState3 && switchState5 == 1) || 
   (switchState4 && switchState5 == 1)) ) {
   
   multiple_switches(array5,2,1);
   }
   
   */



  if (switchState2 == 1) { 
    switch2a(array2,16,10);
  }

  if (switchState3 == 1) {
    switch3a(array3,7,10);
  }
  if (switchState4 == 1) {
    switch4a(array4,15,10);
  }
  if (switchState5 == 1) {
    switch2a(array2,16,10);
    switch3a(array3,7,10);
    switch4a(array4,15,10);
  }  
}

Not a direct response to your problem more a comment of making some improvements to the readability and maintainability of your code.

First of all having the compiler determine the number of elements in array is going to be more accurate, less error prone and more readable than hard-coding number all over.

The number of elements in an array canbe determined by the compiler at compile using for example -

int pinCount = sizeof(ledPins) / sizeof(pinCount[0]);

This says determine the number of bytes in the array.

Divide that by the number of bytes in the first element of the array, after all an array will always have at least 1 entry.

Assign that into the variable ‘pinCount’

‘pinCount’ could be declared as a compile time constant with …

const size_t pinCount = sizeof(ledPins) / sizeof(pinCount[0]);

… thus not using any of your precious RAM. The ‘int’ was changed to ‘size_t’ which is the ‘type’ returned by the ‘sizeof’ compile-time operator.

This can then be generalized into a Preprocessor Macro to enhance readablility of code and reduce the use of seemingly ‘magic’ numbers through out your code with -

#define ARRAY_ENTRIES(ARRAY)	(sizeof(ARRAY) / sizeof(ARRAY[0]))
const size_t pinCount = ARRAY_ENTRIES(ledPins);

Ahhh, what?

void setup()
{
    // initialize the LED pin as an output:

    for ( int column_number = 0; column_number < pinCount; column_number++ )
    {
        pinMode(ledPins[column_number], OUTPUT);

        // initialize the switch pin as an input:
        pinMode(switch2pin, INPUT);
        pinMode(switch3pin, INPUT);
        pinMode(switch4pin, INPUT);
        pinMode(switch5pin, INPUT);

        Serial.begin(9600);
    }
}

You probably meant -

void setup()
{
    Serial.begin(9600);

    // initialize the LED pin as an output:

    for ( int column_number = 0; column_number < ARRAY_ENTRIES(ledPins); column_number++ )
    {
        pinMode(ledPins[column_number], OUTPUT);
    }

    // initialize the switch pin as an input:
    pinMode(switch2pin, INPUT);
    pinMode(switch3pin, INPUT);
    pinMode(switch4pin, INPUT);
    pinMode(switch5pin, INPUT);
}

Does any of this make sense to you or would your prefer I stop posting?

Andy I thank you for the progress you have made, please post the final code when you have it all up and working the way you what. I will reformat you code and take a look at wht you have accomplished. Looking forward to your next post on this subject. :slight_smile:

Andy
I got your program to work for me just a few mods for my situation you can look the code over if you want me to post it. And see if it helps you. I have to re-think my situation because this idea just won't work for me. I need to control 7 different messages and some have to be displayed at the same time. So it is probably going to take me more than on display to do this.
Thanks for the help.