I just copied and pasted your code. No changes except: commenting out expression_parser.h as I don’t have that library, and the line in loop() that uses it, replacing it with an arbitrary number.
//#include "expression_parser.h"
#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 16, 2);
// Khai báo ma trận bàn phím
const byte ROWS = 4; //4 dòng
const byte COLS = 4; //4 cột
char keys[ROWS][COLS] =
{
{'1', '2', '3', '+'},
{'4', '5', '6', '-'},
{'7', '8', '9', '*'},
{'.', '0', '=', '/'}
};
byte rowPins[ROWS] = {10, 9, 8, 7};
byte colPins[COLS] = {6, 5, 4, 3};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
String s = "";
char ex[16];
void setup()
{
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
}
int cur = 0;
bool enter = false;
void loop() {
char key = keypad.getKey();
// Kiểm tra nêu phím đã được nhấn.
if ((key != '=') && (key != NO_KEY) )
{
if (!enter)
{
Serial.println(key);
if (key == '/')
lcd.print(':');
else if (key == '*')
lcd.print('x');
else
lcd.print(key);
s = s + key;
cur++;
lcd.setCursor(cur, 0);
}
else
{
lcd.setCursor(0, 0);
lcd.print("");
enter = false;
lcd.setCursor(0, 0);
cur = 0;
lcd.print(key);
s = "";
s = s + key;
cur++;
lcd.setCursor(cur, 0);
}
}
else if (key == '=')
{
enter = true;
// Kiểm tra nhập sai
if ((s[0] == '=') || (s[0] == '/') || (s[0] == '*') || (s[0] == '.'))
{
lcd.setCursor(0, 1);
lcd.print("Error");
}
else
{
lcd.setCursor(0, 1);
lcd.print("");
s.toCharArray(ex, 16);
Serial.println(s);
//double re = parse_expression(ex);
double re = 12234;
String check = String(re);
if (check.length() > 15)
{
lcd.setCursor(0, 1);
lcd.print("Overflow");
}
else
{
Serial.println(re);
lcd.setCursor(0, 1);
lcd.print("=");
lcd.print(re);
}
}
}
}
Sketch uses 10398 bytes (32%) of program storage space. Maximum is 32256 bytes.
Global variables use 595 bytes (29%) of dynamic memory, leaving 1453 bytes for local variables. Maximum is 2048 bytes.