0% found this document useful (0 votes)
23 views3 pages

Projwithnewlcd

Uploaded by

hasunbriren
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views3 pages

Projwithnewlcd

Uploaded by

hasunbriren
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <LiquidCrystal.

h>
#include <Keypad.h>
#include <DFRobot_RGBLCD1602.h>

LiquidCrystal lcd(14, 15, 16, 17, 18, 19);


DFRobot_RGBLCD1602 lcd2(16, 2); // Initializes the second LCD with I2C

const byte ROWS = 4;


const byte COLS = 3;
char keys[ROWS][COLS] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};

byte rowPins[ROWS] = {2, 3, 4, 5};


byte colPins[COLS] = {6, 7, 8};

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

int num1 = 0;
int num2 = 0;
bool isNum1 = true;
int col = 0;

// Define pin connections


const int carryInFirst = 12;
const int carryInSecond = 11;
const int carryOutPinSecond = 10;
const int sumPinsLower[4] = {38, 40, 42, 44};
const int sumPinsUpper[4] = {45, 43, 41, 39};
const int aPinsLower[4] = {22, 24, 26, 28};
const int aPinsUpper[4] = {46, 48, 50, 52};
const int bPinsLower[4] = {30, 32, 34, 36};
const int bPinsUpper[4] = {53, 51, 49, 47};

void setup() {
for (int i = 0; i < 4; i++) {
pinMode(sumPinsLower[i], INPUT);
pinMode(sumPinsUpper[i], INPUT);
}
pinMode(carryOutPinSecond, INPUT);

lcd.begin(16, 2);
lcd2.init();
lcd2.setRGB(255, 0, 0); // Set RGB backlight color for second LCD
lcd.print("Enter values:");
lcd2.print("Enter values:"); // Show initial message on both LCDs
delay(2000);
lcd.clear();
lcd2.clear();
}

void loop() {
char key = keypad.getKey();

if (key) {
if (key == '#') {
int sum = readResultFrom7483s();
bool carryOut = digitalRead(carryOutPinSecond);

lcd.clear();
lcd2.clear();
lcd.setCursor(0, 0);
lcd2.setCursor(0, 0);
lcd.print("Sum: ");
lcd2.print("Sum: ");
lcd.print(sum);
lcd2.print(sum);
lcd.setCursor(0, 1);
lcd2.setCursor(0, 1);
lcd.print("Carry Out: ");
lcd2.print("Carry Out: ");
lcd.print(carryOut);
lcd2.print(carryOut);
delay(5000);

num1 = 0;
num2 = 0;
isNum1 = true;
col = 0;
lcd.clear();
lcd2.clear();
lcd.print("Enter values:");
lcd2.print("Enter values:");
delay(2000);
lcd.clear();
lcd2.clear();
} else if (key == '*') {
isNum1 = false;
col = 0;
lcd.setCursor(col, 1);
lcd2.setCursor(col, 1);
} else {
if (isNum1) {
num1 = num1 * 10 + (key - '0');
lcd.setCursor(col, 0);
lcd2.setCursor(col, 0);
} else {
num2 = num2 * 10 + (key - '0');
lcd.setCursor(col, 1);
lcd2.setCursor(col, 1);
}
lcd.print(key);
lcd2.print(key);
col++;
}
}
delay(100);
}

void setInputsTo7483s(int a, int b) {


for (int i = 0; i < 4; i++) {
pinMode(aPinsLower[i], OUTPUT);
pinMode(bPinsLower[i], OUTPUT);
digitalWrite(aPinsLower[i], (a >> i) & 1);
digitalWrite(bPinsLower[i], (b >> i) & 1);
}

for (int i = 0; i < 4; i++) {


pinMode(aPinsUpper[i], OUTPUT);
pinMode(bPinsUpper[i], OUTPUT);
digitalWrite(aPinsUpper[i], (a >> (i + 4)) & 1);
digitalWrite(bPinsUpper[i], (b >> (i + 4)) & 1);
}
}

int readResultFrom7483s() {
setInputsTo7483s(num1, num2);

int sumLower = 0;
for (int i = 0; i < 4; i++) {
sumLower |= (digitalRead(sumPinsLower[i]) << i);
}

int sumUpper = 0;
for (int i = 0; i < 4; i++) {
sumUpper |= (digitalRead(sumPinsUpper[i]) << i);
}

return (sumUpper << 4) | sumLower;


}

You might also like