#include<LiquidCrystal_I2C.h>
#include<Wire.h>
#include <Keypad.h>
LiquidCrystal_I2C lcd(0x27,16,2);
const byte row=4;
const byte col=4;
char arr[row][col]={
{'1','2','3','+'},
{'4','5','6','-'},
{'7','8','9','*'},
{'c','0','e','/'}
};
byte rowpin[row]={2,3,4,5};
byte colpin[col]={6,7,8,9};
Keypad mykey=Keypad(makeKeymap(arr),rowpin,colpin,row,col);
String text;
int total=0;
void setup() {
// put your setup code here, to run once:
lcd.begin(16,2);
lcd.backlight();
lcd.setCursor(1,0);
lcd.print("calculeter...");
delay(2000);
lcd.clear();
}
void loop() {
// put your main code here, to run repeatedly:
char key=mykey.getKey();
if(key !='+' || key !='-' || ket !='*' || key !='/' || key !='e' || key!='c' )
{
text+=key;
}
else if(key=='+')
{
total+=int(text);
text='';
}
else if(key=='-')
{
total-=int(text);
text='';
}
else if(key=='e')
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Result=");
lcd.setCursor(0,7);
print(total)
text='' ;
}
else if (key=='c')
{
lcd.clear();
text='';
}
lcd.setCursor(0,0);
lcd.print(text);
delay(100);
}