#define SEG0 15
#define SEG1 2
#define SEG2 0
#define SEG3 4
#define SEG4 16
#define SEG5 17
#define SEG6 5
#define SEG7 18
#define SEG8 19
#define SEG9 21
#define SEG10 22
#define SEG11 23
#define SEG12 32
#define SEG13 33
#define SEG14 25
#define COM0 26
#define COM1 27
#define COM2 14
#define COM3 12
#define ComNum 4
#define SegNum 15
int SEG = 0;
int COM = 0;
int lcdA1;
int lcdB1;
int lcdC1;
int lcdD1;
int lcdE1;
int lcdF1;
int lcdG1;
int lcdA2;
int lcdB2;
int lcdC2;
int lcdD2;
int lcdE2;
int lcdF2;
int lcdG2;
int lcdA3;
int lcdB3;
int lcdC3;
int lcdD3;
int lcdE3;
int lcdF3;
int lcdG3;
int lcdA4;
int lcdB4;
int lcdC4;
int lcdD4;
int lcdE4;
int lcdF4;
int lcdG4;
int dot2;
int dot3;
int dot4;
int negative;
float finalValue = 0;
byte segState[SegNum];
byte comState[ComNum];
byte SegPinArray[SegNum] = {SEG0, SEG1, SEG2, SEG3, SEG4, SEG5, SEG6, SEG7, SEG8, SEG9, SEG10, SEG11, SEG12, SEG13, SEG14};
byte ComPinArray[ComNum] = {COM0, COM1, COM2, COM3};
void setup() {
// Begin Serial
Serial.begin(115200);
// Initialize Segment Pins
for (int i = 0; i < SegNum; i++) {
pinMode(SegPinArray[i], INPUT_PULLUP);
}
// Initialize Common Pins
for (int ii = 0; ii < ComNum; ii++) {
pinMode(ComPinArray[ii], INPUT_PULLUP);
}
}
void readSegArray(byte segState[]) {
for (int i = 0; i < SegNum; i++) {
segState[i] = digitalRead(SegPinArray[i]);
}
}
void readComArray(byte comState[]) {
for (int i = 0; i < ComNum; i++) {
comState[i] = digitalRead(ComPinArray[i]);
}
}
void stateArray(int segmentPin, int commonPin){
switch (segmentPin){
//Seg0
case 0:
switch(segState[segmentPin]){
case 0:
break;
case 1:
switch(commonPin){
//Com0
case 0:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
Serial.println("Timer");
break;
}
break;
//Com1
case 1:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
Serial.println("Min");
break;
}
break;
//Com2
case 2:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
Serial.println("Flashlight");
break;
}
break;
//Com3
case 3:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
Serial.println("Max");
break;
}
break;
}
break;
}
break;
//Seg1
case 1:
switch(segState[segmentPin]){
case 0:
break;
case 1:
switch(commonPin){
//Com0
case 0:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
Serial.println("Farenheit");
break;
}
break;
//Com1
case 1:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
Serial.println("Celsius");
break;
}
break;
//Com2
case 2:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
Serial.println("hFE");
break;
}
break;
//Com3
case 3:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
Serial.println("NCV");
break;
}
break;
}
break;
}
break;
//Seg2
case 2:
switch(segState[segmentPin]){
case 0:
break;
case 1:
switch(commonPin){
//Com0
case 0:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
Serial.println("Amperes");
break;
}
break;
//Com1
case 1:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
Serial.println("Voltage");
break;
}
break;
//Com2
case 2:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
Serial.println("Hertz");
break;
}
break;
//Com3
case 3:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
Serial.println("Battery Low");
break;
}
break;
}
break;
}
break;
//Seg3
case 3:
switch(segState[segmentPin]){
case 0:
break;
case 1:
switch(commonPin){
//Com0
case 0:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
Serial.println("Farad");
break;
}
break;
//Com1
case 1:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
Serial.println("Ohm");
break;
}
break;
//Com2
case 2:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
Serial.println("Up");
break;
}
break;
//Com3
case 3:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
Serial.println("High Voltage");
break;
}
break;
}
break;
}
break;
//Seg4
case 4:
switch(segState[segmentPin]){
case 0:
break;
case 1:
switch(commonPin){
//Com0
case 0:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
Serial.println("Milli");
break;
}
break;
//Com1
case 1:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
Serial.println("Percent");
break;
}
break;
//Com2
case 2:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
Serial.println("Mega");
break;
}
break;
//Com3
case 3:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
Serial.println("Continuity");
break;
}
break;
}
break;
}
break;
//Seg5
case 5:
switch(segState[segmentPin]){
case 0:
break;
case 1:
switch(commonPin){
//Com0
case 0:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
Serial.println("Micro");
break;
}
break;
//Com1
case 1:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
Serial.println("Nano");
break;
}
break;
//Com2
case 2:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
Serial.println("Kilo");
break;
}
break;
//Com3
case 3:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
Serial.println("Diode");
break;
}
break;
}
break;
}
break;
//Seg6
case 6:
switch(segState[segmentPin]){
case 0:
break;
case 1:
switch(commonPin){
//Com0
case 0:
switch(comState[commonPin]){
case 0:
lcdD1 = 0;
break;
case 1:
//edit here
lcdD1 = 1;
break;
}
break;
//Com1
case 1:
switch(comState[commonPin]){
case 0:
lcdC1 = 0;
break;
case 1:
//edit here
lcdC1 = 1;
break;
}
break;
//Com2
case 2:
switch(comState[commonPin]){
case 0:
lcdG1 = 0;
break;
case 1:
//edit here
lcdG1 = 1;
break;
}
break;
//Com3
case 3:
switch(comState[commonPin]){
case 0:
lcdB1 = 0;
break;
case 1:
//edit here
lcdB1 = 1;
break;
}
break;
}
break;
}
break;
//Seg7
case 7:
switch(segState[segmentPin]){
case 0:
break;
case 1:
switch(commonPin){
//Com0
case 0:
switch(comState[commonPin]){
case 0:
dot2 = 0;
break;
case 1:
//edit here
dot2 = 1;
break;
}
break;
//Com1
case 1:
switch(comState[commonPin]){
case 0:
lcdE1 = 0;
break;
case 1:
//edit here
lcdE1 = 1;
break;
}
break;
//Com2
case 2:
switch(comState[commonPin]){
case 0:
lcdF1 = 0;
break;
case 1:
//edit here
lcdF1 = 1;
break;
}
break;
//Com3
case 3:
switch(comState[commonPin]){
case 0:
lcdA1 = 0;
break;
case 1:
//edit here
lcdA1 = 1;
break;
}
break;
}
break;
}
break;
//Seg8
case 8:
switch(segState[segmentPin]){
case 0:
break;
case 1:
switch(commonPin){
//Com0
case 0:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
lcdD2 = 1;
break;
}
break;
//Com1
case 1:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
lcdC2 = 1;
break;
}
break;
//Com2
case 2:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
lcdG2 = 1;
break;
}
break;
//Com3
case 3:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
lcdB2 = 1;
break;
}
break;
}
break;
}
break;
//Seg9
case 9:
switch(segState[segmentPin]){
case 0:
break;
case 1:
switch(commonPin){
//Com0
case 0:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
dot3 = 1;
break;
}
break;
//Com1
case 1:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
lcdE2 = 1;
break;
}
break;
//Com2
case 2:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
lcdF2 = 1;
break;
}
break;
//Com3
case 3:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
lcdA2 = 1;
break;
}
break;
}
break;
}
break;
//Seg10
case 10:
switch(segState[segmentPin]){
case 0:
break;
case 1:
switch(commonPin){
//Com0
case 0:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
lcdD3 = 1;
break;
}
break;
//Com1
case 1:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
lcdC3 = 1;
break;
}
break;
//Com2
case 2:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
lcdG3 = 1;
break;
}
break;
//Com3
case 3:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
lcdB3 = 1;
break;
}
break;
}
break;
}
break;
//Seg11
case 11:
switch(segState[segmentPin]){
case 0:
break;
case 1:
switch(commonPin){
//Com0
case 0:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
dot4 = 1;
break;
}
break;
//Com1
case 1:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
lcdE3 = 1;
break;
}
break;
//Com2
case 2:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
lcdF3 = 1;
break;
}
break;
//Com3
case 3:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
lcdA3 = 1;
break;
}
break;
}
break;
}
break;
//Seg12
case 12:
switch(segState[segmentPin]){
case 0:
break;
case 1:
switch(commonPin){
//Com0
case 0:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
lcdD4 = 1;
break;
}
break;
//Com1
case 1:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
lcdC4 = 1;
break;
}
break;
//Com2
case 2:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
lcdG4 = 1;
break;
}
break;
//Com3
case 3:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
lcdB4 = 1;
break;
}
break;
}
break;
}
break;
//Seg13
case 13:
switch(segState[segmentPin]){
case 0:
break;
case 1:
switch(commonPin){
//Com0
case 0:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
Serial.println("Negative");
negative = 1;
break;
}
break;
//Com1
case 1:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
lcdE4 = 1;
break;
}
break;
//Com2
case 2:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
lcdF4 = 1;
break;
}
break;
//Com3
case 3:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
lcdA4 = 1;
break;
}
break;
}
break;
}
break;
//Seg14
case 14:
switch(segState[segmentPin]){
case 0:
break;
case 1:
switch(commonPin){
//Com0
case 0:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
Serial.println("AC");
break;
}
break;
//Com1
case 1:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
Serial.println("DC");
break;
}
break;
//Com2
case 2:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
Serial.println("Auto");
break;
}
break;
//Com3
case 3:
switch(comState[commonPin]){
case 0:
break;
case 1:
//edit here
break;
}
break;
}
break;
}
break;
}
}
void convBinDec1stDigi(){
//0
if(lcdA1 == 1 && lcdB1 == 1 && lcdC1 == 1 && lcdD1 == 1 && lcdE1 == 1 && lcdF1 ==1 && lcdG1 ==0){
finalValue = 2;
}
}
void loop() {
readSegArray(segState);
readComArray(comState);
convBinDec1stDigi();
Serial.print("LCD State: ");
Serial.print("A1=");
Serial.print(lcdA1);
Serial.print(" ,B1=");
Serial.print(lcdB1);
Serial.print(" ,C1=");
Serial.print(lcdC1);
Serial.print(" ,D1=");
Serial.print(lcdD1);
Serial.print(" ,E1=");
Serial.print(lcdE1);
Serial.print(" ,F1=");
Serial.print(lcdF1);
Serial.print(", G1=");
Serial.print(lcdG1);
Serial.print(" ");
Serial.println(finalValue);
stateArray(0,0);
stateArray(0,1);
stateArray(0,2);
stateArray(0,3);
stateArray(1,0);
stateArray(1,1);
stateArray(1,2);
stateArray(1,3);
stateArray(2,0);
stateArray(2,1);
stateArray(2,2);
stateArray(2,3);
stateArray(3,0);
stateArray(3,1);
stateArray(3,2);
stateArray(3,3);
stateArray(4,0);
stateArray(4,1);
stateArray(4,2);
stateArray(4,3);
stateArray(5,0);
stateArray(5,1);
stateArray(5,2);
stateArray(5,3);
stateArray(6,0);
stateArray(6,1);
stateArray(6,2);
stateArray(6,3);
stateArray(7,0);
stateArray(7,1);
stateArray(7,2);
stateArray(7,3);
stateArray(8,0);
stateArray(8,1);
stateArray(8,2);
stateArray(8,3);
stateArray(9,0);
stateArray(9,1);
stateArray(9,2);
stateArray(9,3);
stateArray(10,0);
stateArray(10,1);
stateArray(10,2);
stateArray(10,3);
stateArray(11,0);
stateArray(11,1);
stateArray(11,2);
stateArray(11,3);
stateArray(12,0);
stateArray(12,1);
stateArray(12,2);
stateArray(12,3);
stateArray(13,0);
stateArray(13,1);
stateArray(13,2);
stateArray(13,3);
stateArray(14,0);
stateArray(14,1);
stateArray(14,2);
stateArray(14,3);
stateArray(10,0);
stateArray(10,1);
stateArray(10,2);
stateArray(10,3);
delay(500); // Delay for readability
}