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;
}