#include<LiquidCrystal.h>
int rs = 7;
int en = 8;
int d4 = 9;
int d5 = 10;
int d6 = 11;
int d7 = 12;
int d = 1000;
String msg1 = "Enter first num: ";
String msg2 = "Enter second num: ";
String msg3 = "Enter operator: ";
float firstnum;
float secondnum;
float ans;
String op;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
lcd.begin(16, 2);
}
void loop() {
// put your main code here, to run repeatedly:
lcd.setCursor(0, 0);
lcd.print(msg1);
while (Serial.available() == 0) {}
firstnum = Serial.parseFloat();
Serial.find('\n'); // skip the remaining characters until end of line
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(msg2);
while (Serial.available() == 0) {}
secondnum = Serial.parseFloat();
Serial.find('\n'); // skip the remaining characters until end of line
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Input operator(+,-,*,/)");
while (Serial.available() == 0) {}
op = (char)Serial.read();
Serial.find('\n'); // skip the remaining characters until end of line
if (op == "+")
{
ans = firstnum + secondnum;
}
if (op == "-")
{
ans = firstnum - secondnum;
}
if (op == "*")
{
ans = firstnum * secondnum;
}
if (op == "/")
{
ans = firstnum / secondnum;
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(firstnum);
lcd.print(op);
lcd.print(secondnum);
lcd.print("=");
lcd.print(ans);
delay(2000);
}