driving 4511 7 seg LED

I've got a program that compares an input array to another array and when it finds a row match it generates a 4 digit binary number from another array (based on the matched row number) to drive a 4511 and 7 seg LED.

I know the compare arrays are working (serial monitor/attached LED's confirm this). I know the 4511 wiring is good (tested with a simple counting program) but now my 4 op's seem good on the serial monitor and change with the input changes but don't show anything on the 7 seg.

Its like the 4511 doesn't like the low/high (1/0) inputs any more?

   int Bin1 = 12; //These are all identifying the  inputs of
   int Bin2 = 8; //the 4511 Seven Segment Decoder
   int Bin3 = 9;
  int Bin4 = 11;

 int buttonPin = 2;     //gear selector inputs
int buttonPin1 = 3;     
int buttonPin2 = 4;     
int buttonPin3 = 5;     
int buttonPin4 = 6;
int buttonPin5 = 7;     
int buttonPin6 = 31;

int opState; 
   int opState1; 
   int opState2; 
   int opState3; 

int buttonState; 
   int buttonState1; 
   int buttonState2; 
   int buttonState3; 
   int buttonState4; 

  // int opState; 
  // int opState1; 
  // int opState2; 
  // int opState3; 
  // int opState4; 

int rowNum;

int ipArray [] ={LOW,LOW,LOW,LOW,LOW,LOW,LOW};//initialise ipArray to zeros
int compArray [7] [7] { 
{LOW,LOW,LOW, LOW, LOW, LOW,HIGH},       //Neutral
{LOW,LOW,LOW, LOW, LOW, HIGH, LOW},       //Gear1
{LOW,LOW,LOW, LOW, HIGH, LOW, LOW},       //Gear2
{LOW,LOW,LOW, HIGH, LOW, LOW, LOW},       //Gear3
{LOW,LOW,HIGH, LOW, LOW, LOW, LOW},       //Gear4
{LOW,HIGH,LOW, LOW, LOW, LOW, LOW}, //Gear5
{HIGH,LOW,LOW, LOW, LOW, LOW, LOW}, //Gear6
};
int opArray [7] [4] { 
  {B0, B0,B0, B0},       //row0
  {B0, B0,B0, B1},       //row1
  {B0, B0,B1, B0},       //row2
  {B0, B0,B1, B1},       //row3
  {B0, B1,B0, B0},       //row4
  {B0, B1,B0, B1},       //row5
  {B0, B1,B1, B0},       //row6
};

 void setup() //Enters the setup phase
 {
   pinMode(Bin1, OUTPUT); // sets up  output one as a digital output
   pinMode(Bin2, OUTPUT); //and so on...
   pinMode(Bin3, OUTPUT);
   pinMode(Bin4, OUTPUT);
   
   pinMode(buttonPin, INPUT);
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);
  pinMode(buttonPin4, INPUT);
  pinMode(buttonPin5, INPUT);
  pinMode(buttonPin6, INPUT);

  int buttonState = LOW; 
   int buttonState1 = LOW; 
   int buttonState2 = LOW; 
   int buttonState3 = LOW; 
   int buttonState4 = LOW; 
 int buttonState5 = LOW; 
   int buttonState6 = LOW; 
   
Serial.begin(9600);
 }

 void loop() 
 {
   ipArray [0] = digitalRead (buttonPin );//populate 2d array //  
ipArray [1] = digitalRead (buttonPin1 );//populate 2d array //   
ipArray [2] = digitalRead (buttonPin2 );//populate 2d array // 
ipArray [3] = digitalRead (buttonPin3 );//populate 2d array //    
ipArray [4] = digitalRead (buttonPin4 );//populate 2d array //    
ipArray [3] = digitalRead (buttonPin5 );
ipArray [3] = digitalRead (buttonPin6 );
delay(15);

Serial.println();
Serial.println("Print ipArray After Overwriting The Content with digitalRead, ");
  for (int a = 0; a < 7; a++) 
  {
  Serial.print(ipArray [a] );
  
      //Serial.print(' ');//prints tabs between array elements
  Serial.println();
  }
rowNum = compare();//return from compare function is assigned to integer rowNum

Serial.print("return Row number from Compare array = ");
Serial.print (rowNum);
Serial.println("");

opState = opArray [rowNum] [0];
opState1 = opArray [rowNum] [1];
opState2 = opArray [rowNum] [2];
opState3 = opArray [rowNum] [3];

Serial.println ("Confirmed output state");
Serial.println ("");
Serial.println (opState);
Serial.println (opState1);
Serial.println (opState2);
Serial.println (opState3);

digitalWrite (Bin1,opArray [rowNum][0]);
digitalWrite (Bin2,opArray [rowNum][1]);
digitalWrite (Bin3,opArray [rowNum][2]);
digitalWrite (Bin4,opArray [rowNum][3]);

 }

 //compare each row of compArray with ipArray
 int compare()//now returns value of row and assigns to rowNum
{ 
 int row; //row and column are locals to FOR
  for ( row = 0; row < 7; row++ )   // each row in turn
  {
   int col;
    for ( col = 0; col < 7; col++)   // each column in turn
    {
      if (compArray[row][col] != ipArray[col])//increments to first row then increments columns and compares each position against ipArray column values. Switches to next row and repeats
      {
        break;  // if not equal. reset and change row/column. No need to look at remaining columns
      }
    }
    if (col == 7)  // if it gets to last column with no mismatch 
    {
      break; // correct row is found. No need to look at remaining rows
    }
  }
   Serial.println();
  if (row < 7)
 {
    Serial.print("They match at row ");
    Serial.println(row);//row is assigned in first FOR loop when match is found
 }
  else
  {
    Serial.println("No match found.");
  }
  return row;
}

I found one problem. I wasn't starting my arrays at 0 (so using 7 column count instead of 6).

Some number now fire Ok and some don't?

Also although when I measure an input state it is high (buttonPin3) it still reports a 0??

Confused?

kpg:
I found one problem. I wasn't starting my arrays at 0 (so using 7 column count instead of 6).

Some number now fire Ok and some don't?

Also although when I measure an input state it is high (buttonPin3) it still reports a 0??

Confused?

void loop()
{
  ipArray [0] = digitalRead (buttonPin );//populate 2d array //
  ipArray [1] = digitalRead (buttonPin1 );//populate 2d array //
  ipArray [2] = digitalRead (buttonPin2 );//populate 2d array //
  ipArray [3] = digitalRead (buttonPin3 );//populate 2d array //
  ipArray [4] = digitalRead (buttonPin4 );//populate 2d array //
  ipArray [3] = digitalRead (buttonPin5 );
  ipArray [3] = digitalRead (buttonPin6 );
  delay(15);
  ....

Re-read what you've coded there. line by line :wink:

And once the indexes are fixed, note that will be 2x much faster if you store your LOW and HIGH arrays as bytes versus integer and if you want to be 8x even faster use 7 bits of a byte to represent your 7 states - for example{LOW,LOW,LOW, LOW, LOW, LOW,HIGH},      //Neutralwould becomeB0000001, // Neutralthen you compare 1 line with just 1 byte == compare

Now if you were to notice that you basically have 1 byte HIGH and the other low, you could just count the number of 0 at the right of the byte you build and you don’ t need the array at all (GCC offers a BUILTIN function __builtin_ctz() to count those)

Do you have pulldown resistors on the button pins?