In this lesson we show you our solution to the assignment in Lesson 48 to build a simple calculator with an LCD Output. The video steps you through the project build step-by-step.
In the project, the following schematic is used.
If you need the kit we are using in this series of lessons, you can get it HERE.
And this is the code developed in the video.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | #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() { lcd.setCursor(0,0); lcd.print("Input 1st 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("Input(+,-,*,/)"); while (Serial.available()==0){ } op=Serial.readString(); if (op=="+"){ answer=firstNum+secNum; } if (op=="-"){ answer=firstNum-secNum; } if (op=="*"){ answer=firstNum*secNum; } 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(); } |