#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
int Menu = 0;
float Area;
float Perimeter;
String Shape_Opt;
String Calc_Opt;
// Calculations for the Rectangle
float lR;
float bR;
float Area_R = lR * bR;
float Perimeter_R = 2*lR + 2*bR;
// Calculations for the Triangle
float base;
float height;
float slopes;
float Area_T = 0.5 * base * height;
float Perimeter_T = 2 * slopes + base;
//Calculation for the Circle
float radius;
float pi = 3.142;
float Area_C = pi * pow(radius,2);
float Perimeter_C = 2 * 3.142 * radius;
// Now to setup the program.
void setup() {
lcd.begin(20, 4);
lcd.backlight();
Serial.begin(115200);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Welcome, let's Calc!");
lcd.setCursor(0,1);
lcd.print("Calc. in cm.");
delay(2000);
lcd.clear();
lcd.print("Triangle");
lcd.setCursor(0, 1);
lcd.print("Rectangle");
lcd.setCursor(0, 2);
lcd.print("Circle");
Serial.println("Type in the Shape from the Options.\n");
Serial.println("Triangle is an Isosceles triangle.");
}
// Now to the logic of the program.
void loop(){
String Shape_Opt;
if (Serial.available()){
String Shape_Opt = Serial.readString();
if (Shape_Opt == "Rectangle"){
float Area = Area_R;
float Perimeter = Perimeter_R;
lcd.clear();
lcd.print("Select Calc.");
lcd.setCursor(0, 1);
lcd.print("Area");
lcd.setCursor(0, 2);
lcd.print("Perimeter");
Serial.println("Type in the Calculation to perform.\n");
Serial.println("Calc_Opt: ");
String Calc_Opt;
if (Serial.available()){
String Calc_Opt = Serial.readString();
if (Calc_Opt == "Area"){
lcd.print("Input Values");
Serial.println("Length= ");
float lR;
Serial.parseFloat();
Serial.println("Breadth= ");
float bR;
Serial.parseFloat();
lcd.setCursor(0,0);
lcd.print("Length= ");
lcd.print(lR);
lcd.setCursor(0,1);
lcd.print("Breadth= ");
lcd.print(bR);
lcd.setCursor(0,3);
lcd.print("Area= ");
lcd.print(Area);
lcd.print("cm");
}
}
}
}
}