#include <LiquidCrystal_I2C.h>
// Initialize a LiquidCrystal object for the LCD display with the following pin connections:
// (RS, E, D4, D5, D6, D7)
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Define global variables and arrays
int gateInput1, gateInput2, i, j, k;
bool inputTable[4][2] = {0, 0, 0, 1, 1, 0, 1, 1};
int outputTable[5][4] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 6};
bool foundMatch, database[4][5] = {0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0};
String icName; // To store the IC name
void setup() {
// Initialize the LCD display with 16 columns and 2 rows
lcd.init(); //initialize the lcd
lcd.backlight(); //open the backlight
lcd.clear(); // Clear the LCD screen
lcd.setCursor(0, 0);
lcd.print("PUSH B TO TEST");
lcd.setCursor(0, 1);
lcd.print("B1 NOT B2 NOR");
delay(1000);
lcd.clear(); // Clear the LCD screen
lcd.setCursor(0, 0);
lcd.print("B3 AND OR");
lcd.setCursor(0, 1);
lcd.print("NAND & EXOR");
delay(1000);
lcd.setCursor(0, 0);
lcd.print("B4 INDUCTANCE");
lcd.setCursor(0, 1);
lcd.print("B5 CAPACITANCE");
delay(1000);
Serial.begin(9600); // Initialize the serial communication
}
void loop() {
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
//MODE I NOT
if(digitalRead(6)==LOW)
{
lcd.clear();
pinMode(2, INPUT);
pinMode(3, OUTPUT);
pinMode(1, OUTPUT);
pinMode(0, INPUT);
pinMode(21, OUTPUT);
pinMode(20, INPUT);
pinMode(17, INPUT);
pinMode(16, OUTPUT);
pinMode(18, INPUT);
pinMode(19, OUTPUT);
pinMode(26, INPUT);
pinMode(22, OUTPUT);
digitalWrite(3, LOW);
digitalWrite(1, LOW);
digitalWrite(21, LOW);
digitalWrite(16, LOW);
digitalWrite(19, LOW);
digitalWrite(22, LOW);
if(digitalRead(2)== HIGH)
{
lcd.setCursor(0,0);
lcd.print("1.NOT");
delay(100);
}
else
{
lcd.setCursor(0,0);
lcd.print("1.BAD");
delay(100);
}
if(digitalRead(0)== HIGH)
{
lcd.setCursor(5,0);
lcd.print("2.NOT");
delay(100);
}
else
{
lcd.setCursor(5,0);
lcd.print("2.BAD");
delay(100);
}
if(digitalRead(20)== HIGH)
{
lcd.setCursor(10,0);
lcd.print("3.NOT");
delay(100);
}
else
{
lcd.setCursor(10,0);
lcd.print("3.BAD");
delay(100);
}
if(digitalRead(17)== HIGH)
{
lcd.setCursor(0,1);
lcd.print("4.NOT");
delay(100);
}
else
{
lcd.setCursor(0,1);
lcd.print("4.BAD");
delay(100);
}
if(digitalRead(18)== HIGH)
{
lcd.setCursor(5,1);
lcd.print("5.NOT");
delay(100);
}
else
{
lcd.setCursor(5,1);
lcd.print("5.BAD");
delay(100);
}
if(digitalRead(26)== HIGH)
{
lcd.setCursor(10,1);
lcd.print("6.NOT");
delay(100);
}
else
{
lcd.setCursor(10,1);
lcd.print("6.BAD");
delay(100);
}
delay(1000);
}
//MODE II NOR
else if(digitalRead(7) == LOW)
{
lcd.clear(); // Clear the LCD screen
lcd.setCursor(0, 0);
// Configure various pins as input and output
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(16, OUTPUT);
pinMode(17, OUTPUT);
pinMode(20, OUTPUT);
pinMode(19, OUTPUT);
pinMode(22, OUTPUT);
pinMode(0, OUTPUT);
pinMode(3, INPUT);
pinMode(18, INPUT);
pinMode(21, INPUT);
pinMode(26, INPUT);
for (i = 0; i < 4; i++) {
outputTable[4][i] = 6; // Initialize the outputTable's fifth row with 6
}
for (i = 0; i < 4; i++) {
// Testing gate 1
digitalWrite(2, inputTable[i][0]);
digitalWrite(1, inputTable[i][1]);
gateInput1 = digitalRead(3);
outputTable[i][0] = gateInput1;
// Testing gate 2
digitalWrite(22, inputTable[i][0]);
digitalWrite(0, inputTable[i][1]);
gateInput2 = digitalRead(26);
outputTable[i][1] = gateInput2;
// Testing gate 3
digitalWrite(20, inputTable[i][0]);
digitalWrite(19, inputTable[i][1]);
gateInput1 = digitalRead(21);
outputTable[i][2] = gateInput1;
// Testing gate 4
digitalWrite(17, inputTable[i][0]);
digitalWrite(16, inputTable[i][1]);
gateInput2 = digitalRead(18);
outputTable[i][3] = gateInput2;
}
for (k = 0; k < 4; k++) {
for (i = 0; i < 5; i++) {
foundMatch = true;
for (j = 0; j < 4; j++) {
// Compare outputTable values with the database
if (outputTable[j][k] != database[j][i]) {
foundMatch = false;
break;
}
}
if (foundMatch) {
outputTable[4][k] = i; // Store the matching result in the fifth row
}
}
}
for (i = 0; i < 4; i++) {
lcd.setCursor((i % 2) * 7, i / 2); // Set the LCD cursor position
lcd.print(i + 1); // Print gate number
lcd.print('.'); // Add a period to separate the gate number and IC name
switch (outputTable[4][i]) {
case 0:
icName = "AND";
break;
case 1:
icName = "OR";
break;
case 2:
icName = "NAND";
break;
case 3:
icName = "NOR";
break;
case 4:
icName = "EXOR";
break;
default:
icName = "BAD";
break;
}
lcd.print(icName + " ");
delay(100);
}
delay(1000);
// Check if all IC names are the same
bool allICsSame = true;
for (i = 1; i < 4; i++) {
if (outputTable[4][i] != outputTable[4][0]) {
allICsSame = false;
break;
}
}
// Display a message based on whether all IC names are the same or not
if (allICsSame) { //Showing the IC models
if(icName=="AND"){
lcd.setCursor(0, 0); // Set cursor to the second line
lcd.clear();
lcd.print("WRONG MODE");
lcd.setCursor(0,1);
lcd.print("PRESS BUTTON 3");
} else if(icName=="OR"){
lcd.setCursor(0, 0); // Set cursor to the second line
lcd.clear();
lcd.print("WRONG MODE");
lcd.setCursor(0,1);
lcd.print("PRESS BUTTON 3");
} else if(icName=="NAND"){
lcd.setCursor(0, 0); // Set cursor to the second line
lcd.clear();
lcd.print("WRONG MODE");
lcd.setCursor(0,1);
lcd.print("PRESS BUTTON 3");
} else if(icName=="EXOR"){
lcd.setCursor(0, 0); // Set cursor to the second line
lcd.clear();
lcd.print("WRONG MODE");
lcd.setCursor(0,1);
lcd.print("PRESS BUTTON 3");
} else if(icName=="NOR"){
lcd.setCursor(0, 0); // Set cursor to the second line
lcd.clear();
lcd.print("IC 7402");
lcd.setCursor(0,1);
lcd.print("ALL GATES ARE OK");
}else if(icName=="BAD"){
lcd.setCursor(0, 0); // Set cursor to the second line
lcd.clear();
lcd.print("BAD IC OR NO");
lcd.setCursor(0, 1); // Set cursor to the second line
lcd.print("IC IS CONNECTED");
}
} else {
lcd.setCursor(0, 0); // Set cursor to the second line
lcd.clear();
lcd.print("ALL GATES ARE");
lcd.setCursor(0, 1);
lcd.print("NOT FUNCTIONAL");
}
delay(1000); // Delay for 1 second before repeating the loop
}
//MODE III OR AND NAND XOR
else if(digitalRead(8) == LOW)
{
lcd.clear(); // Clear the LCD screen
lcd.setCursor(0, 0);
// Configure various pins as input and output
pinMode(3, OUTPUT);
pinMode(2, OUTPUT);
pinMode(17, OUTPUT);
pinMode(18, OUTPUT);
pinMode(20, OUTPUT);
pinMode(21, OUTPUT);
pinMode(22, OUTPUT);
pinMode(26, OUTPUT);
pinMode(1, INPUT);
pinMode(16, INPUT);
pinMode(19, INPUT);
pinMode(0, INPUT);
for (i = 0; i < 4; i++) {
outputTable[4][i] = 6; // Initialize the outputTable's fifth row with 6
}
for (i = 0; i < 4; i++) {
// Testing gate 1
digitalWrite(2, inputTable[i][0]);
digitalWrite(3, inputTable[i][1]);
gateInput1 = digitalRead(1);
outputTable[i][0] = gateInput1;
// Testing gate 2
digitalWrite(22, inputTable[i][0]);
digitalWrite(26, inputTable[i][1]);
gateInput2 = digitalRead(0);
outputTable[i][1] = gateInput2;
// Testing gate 3
digitalWrite(20, inputTable[i][0]);
digitalWrite(21, inputTable[i][1]);
gateInput1 = digitalRead(19);
outputTable[i][2] = gateInput1;
// Testing gate 4
digitalWrite(17, inputTable[i][0]);
digitalWrite(18, inputTable[i][1]);
gateInput2 = digitalRead(16);
outputTable[i][3] = gateInput2;
}
for (k = 0; k < 4; k++) {
for (i = 0; i < 5; i++) {
foundMatch = true;
for (j = 0; j < 4; j++) {
// Compare outputTable values with the database
if (outputTable[j][k] != database[j][i]) {
foundMatch = false;
break;
}
}
if (foundMatch) {
outputTable[4][k] = i; // Store the matching result in the fifth row
}
}
}
for (i = 0; i < 4; i++) {
lcd.setCursor((i % 2) * 7, i / 2); // Set the LCD cursor position
lcd.print(i + 1); // Print gate number
lcd.print('.'); // Add a period to separate the gate number and IC name
switch (outputTable[4][i]) {
case 0:
icName = "AND";
break;
case 1:
icName = "OR";
break;
case 2:
icName = "NAND";
break;
case 3:
icName = "NOR";
break;
case 4:
icName = "EXOR";
break;
default:
icName = "BAD";
break;
}
lcd.print(icName + " ");
delay(100);
}
delay(1000);
// Check if all IC names are the same
bool allICsSame = true;
for (i = 1; i < 4; i++) {
if (outputTable[4][i] != outputTable[4][0]) {
allICsSame = false;
break;
}
}
// Display a message based on whether all IC names are the same or not
if (allICsSame) { //Showing the IC models
if(icName=="AND"){
lcd.setCursor(0, 0); // Set cursor to the second line
lcd.clear();
lcd.print("IC 7408");
lcd.setCursor(0,1);
lcd.print("ALL GATES ARE OK");
} else if(icName=="OR"){
lcd.setCursor(0, 0); // Set cursor to the second line
lcd.clear();
lcd.print("IC 7432");
lcd.setCursor(0,1);
lcd.print("ALL GATES ARE OK");
} else if(icName=="NAND"){
lcd.setCursor(0, 0); // Set cursor to the second line
lcd.clear();
lcd.print("IC 7400");
lcd.setCursor(0,1);
lcd.print("ALL GATES ARE OK");
} else if(icName=="EXOR"){
lcd.setCursor(0, 0); // Set cursor to the second line
lcd.clear();
lcd.print("IC 7486");
lcd.setCursor(0,1);
lcd.print("ALL GATES ARE OK");
} else if(icName=="NOR"){
lcd.setCursor(0, 0); // Set cursor to the second line
lcd.clear();
lcd.print("BAD IC OR NO");
lcd.setCursor(0,1);
lcd.print("IC IS CONNECTED");
}else if(icName=="BAD"){
lcd.setCursor(0, 0); // Set cursor to the second line
lcd.clear();
lcd.print("BAD IC OR NO");
lcd.setCursor(0, 1); // Set cursor to the second line
lcd.print("IC IS CONNECTED");
}
} else {
lcd.setCursor(0, 0); // Set cursor to the second line
lcd.clear();
lcd.print("ALL GATES ARE");
lcd.setCursor(0, 1);
lcd.print("NOT FUNCTIONAL");
}
delay(1000); // Delay for 1 second before repeating the loop
}
else
{
lcd.clear(); // Clear the LCD screen
lcd.setCursor(0, 0);
lcd.print("PUSH B TO TEST");
lcd.setCursor(0, 1);
lcd.print("B1 NOT B2 NOR");
delay(1000);
lcd.clear(); // Clear the LCD screen
lcd.setCursor(0, 0);
lcd.print("B3 AND OR");
lcd.setCursor(0, 1);
lcd.print("NAND & EXOR");
delay(1000);
}
}