#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
int cnt=0;
int tecla=0;
char keys[ROWS][COLS] = {
{ '1', '4', '7', ':' },
{ '2', '5', '8', '0' },
{ '3', '6', '9', ';' },
{ '<', '=', '>', '?' },
};
uint8_t colPins[COLS] = { 23, 19, 18, 17 };
uint8_t rowPins[ROWS] = { 16, 4, 2, 15 };
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS,
COLS);
int numero,num=0,aux,opera=0;
void setup() {
lcd.init();
lcd.setCursor(0,0);
lcd.print("CALCULADORA Steff");
lcd.backlight();
}
void loop() {
tecla=16;
int key = keypad.getKey();
if(key>0){tecla=key -'0';}
if(tecla<10){
num++;
if(num==1)
{
numero=tecla;
}
if(num==2)
{
numero=numero*10+tecla;
}
if(num==3)
{
numero=numero*10+tecla;
}
if(num==4)
{
numero=numero*10+tecla;num=0;
}
}
if(tecla==12){
aux=numero;
opera=1;
num=0;
lcd.setCursor(15,0);
lcd.print("+");
}
if (tecla==11){
if(opera==1){
numero=aux+numero;
lcd.setCursor(15,0);
lcd.print("=");
num=0;
}
}
if(tecla==13){
aux=numero;
opera=2;
num=0;
lcd.setCursor(15,0);
lcd.print("-");
}
if (tecla==11){
if(opera==2){
numero=aux-numero;
lcd.setCursor(15,0);
lcd.print("=");
num=0;
}
}
if(tecla==14){
aux=numero;
opera=3;
num=0;
lcd.setCursor(15,0);
lcd.print("*");
}
if (tecla==11){
if(opera==3){
numero=aux*numero;
lcd.setCursor(15,0);
lcd.print("=");
num=0;
}
}
if(tecla==15){
aux=numero;
opera=4;
num=0;
lcd.setCursor(15,0);
lcd.print("/");
}
if (tecla==11){
if(opera==4){
numero=aux/numero;
lcd.setCursor(15,0);
lcd.print("=");
num=0;
}
}
lcd.setCursor(0,1);
lcd.print(numero);
lcd.print(" ");
}