I am attempting to make a calculator with arduino using a 16x2 Text-LCD and a 4x4 keypad. I've already programmed the part where the arduino board gets input from the keypad and displays characters on the LCD respectively, but I'm struggling to program the part where the '=' button is pressed and the arduino parses the sum and gives the answer. I'm not using the RW lin to read the LCD, instead I am adding characters pressed to a char[] variable. Can you guys please give me some code to parse the inputted characters? Thanks!
EDIT: Code:
#include <LiquidCrystal.h>
#include <Key.h>
#include <Keypad.h>
char keys[4][4]={
'/','x','-','+',
'=','9','6','3',
'0','8','5','2',
'C','7','4','1'
};
byte rowPins[4]={7,6,5,4};
byte colPins[4]={3,2,1,0};
Keypad input=Keypad(makeKeymap(keys),rowPins,colPins,4,4);
LiquidCrystal lcd(8,9,10,11,12,13);
int inputSize=1;
char inputSum[16];
int cursorNum=0;
void setup() {
lcd.begin(16,2);
}
void loop() {
char key = input.getKey();
if(key) {
if(key == 'C') {
lcd.clear();
}else if(key == '=') {
parseInput();
}
else{
lcd.print(key);
inputSum[cursorNum]=key;
cursorNum++;
}
}
}
int result;
void parseInput() {
//Parse code goes here
lcd.setCursor(0,1);
lcd.print(result);
}