Advertisement
DrAungWinHtut

LCD_Calculator.ino

Jul 15th, 2022
1,662
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Programmer : Dr. Aung Win Htut
  3.  * Date       : 16-07-2022
  4.  * Version    : 2.1
  5.  * Note       : In serial monitor, choose the
  6.  *              baud rate 9600 and No line ending
  7.  */
  8. #include <LiquidCrystal.h>
  9. int rs=2;
  10. int en=3;
  11. int d4=8;
  12. int d5=9;
  13. int d6=10;
  14. int d7=11;
  15.  
  16. int seconds = 0;
  17.  
  18. LiquidCrystal lcd(rs,en,d4,d5,d6,d7);
  19.  
  20. float firstNum;
  21. float secNum;
  22. float answer;
  23. String op;
  24.  
  25. void setup()
  26. {
  27.   lcd.begin(16, 2);
  28.   Serial.begin(9600);
  29.  
  30.   lcd.print("hello world");
  31.   delay(1000);
  32. }
  33.  
  34. void loop()
  35. {
  36.   lcd.clear();
  37.   lcd.setCursor(0, 0);
  38.   Serial.println();
  39.   Serial.print("Input 1st Number");
  40.   lcd.print("Input 1st Number");
  41.   while (Serial.available() == 0){  
  42.     //loop to wait until serial data input (No line ending)
  43.   }
  44.   firstNum=Serial.parseFloat();
  45.  
  46.   lcd.setCursor(0,1);
  47.   lcd.print(String(firstNum));
  48.   Serial.print(" : ");
  49.   Serial.println(String(firstNum));
  50.   delay(1000);
  51.   lcd.clear();
  52.  
  53.   lcd.setCursor(0,0);
  54.   Serial.print("Input 2nd Number");
  55.   lcd.print("Input 2nd Number");
  56.   while ( Serial.available() == 0 ){  
  57.     //loop to wait until serial data input (No line ending)
  58.   }  
  59.   secNum=Serial.parseFloat();
  60.  
  61.   Serial.print(" : ");
  62.   Serial.println(String(secNum));
  63.   lcd.setCursor(0,1);  
  64.   lcd.print(String(secNum));
  65.   delay(1000);
  66.   lcd.clear();
  67.  
  68.   lcd.setCursor(0,0);
  69.   Serial.print("Input(+,-,*,/)");
  70.   lcd.print("Input(+,-,*,/)");
  71.   while (Serial.available()==0){  
  72.     //loop to wait until serial data input (No line ending)
  73.   }
  74.   op=Serial.readString();
  75.   Serial.print(" : ");
  76.   Serial.println(op);
  77.  
  78.   if (op == "+"){
  79.     answer=firstNum+secNum;
  80.   }
  81.   if (op=="-"){
  82.     answer=firstNum-secNum;
  83.   }
  84.   if (op=="*"){
  85.     answer=firstNum*secNum;
  86.   }
  87.   if (op=="/") {
  88.     answer=firstNum/secNum;
  89.   }
  90.   lcd.clear();
  91.   Serial.print(firstNum);
  92.   lcd.setCursor(0,0);  
  93.   lcd.print(firstNum);
  94.  
  95.   Serial.print(op);
  96.   lcd.print(op);
  97.  
  98.   Serial.print(secNum);
  99.   lcd.print(secNum);
  100.  
  101.   Serial.print(" = ");
  102.   lcd.print(" = ");
  103.  
  104.   Serial.println(answer);
  105.   lcd.setCursor(0,1);  
  106.   lcd.print(answer);
  107.  
  108.   delay(5000);
  109.   Serial.println("Thank You");
  110.   lcd.setCursor(0,0);
  111.   lcd.clear();
  112.   lcd.print("Thank You");
  113.   delay(1000);
  114.   lcd.clear();
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement