Hi,
I am currently playing around with the arduino and decided to build a calcuatlor with an LCD screen. The code is very straight forward.
The problem is, rather than wait for the second number to be inputted to the serial monitor, it is assuming a '0' and the second while(==0) is being skipped.
Any help would be great.
code below;
#include <LiquidCrystal.h>
int rs=7;
int en=8;
int d4=9;
int d5=10;
int d6=11;
int d7=12;
float firstNum;
float secNum;
float answer;
String op;
LiquidCrystal lcd(rs,en,d4,d5,d6,d7);
void setup() {
// put your setup code here, to run once:
lcd.begin(16,2);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
lcd.setCursor(0,0);
lcd.print("Input Number");
while(Serial.available()==0)
{
}
firstNum=Serial.parseFloat();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Input 2nd Number");
while(Serial.available()==0)
{
}
secNum=Serial.parseFloat();
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" Op(+,-,*,/)");
while(Serial.available()==0)
{
}
op=Serial.readString();
if(op=="+")
{
answer=firstNum+secNum;
}
if(op=="-")
{
answer=firstNum-secNum;
}
if(op=="")
{
answer=firstNumsecNum;
}
if(op=="/")
{
answer=firstNum/secNum;
}
lcd.clear();
lcd.setCursor(0,0);
lcd.print(firstNum);
lcd.print(op);
lcd.print(secNum);
lcd.print("=");
lcd.print(answer);
// lcd.setCursor(0,1);
// lcd.print("thank you");
delay(5000);
lcd.clear();
Calc_LCD.ino (1.25 KB)