Hola me he hecho una calculadora con un lcd y un tecladito y lo tengo casi listo pero al sumar cualquier numero me da 0, me podrian decir en qué me he eqivocado? gracias. La parte de la sua esta completa pero no me lo suma.
#include <Keypad.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
String a = "";
char hexaKeys[ROWS][COLS] = {
{'1','2','3','+'},
{'4','5','6','-'},
{'7','8','9','*'},
{'-','0','=','/'}
};
byte rowPins[ROWS] = {46, 47, 48, 49}; //connect to the row pinouts of
the keypad
byte colPins[COLS] = {50, 51, 52, 53}; //connect to the column pinouts
of the keypad
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins,
ROWS, COLS);
void setup() {
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(199, 1);
// Print a message to the LCD.
}
int suma = 0;
int resta = 0;
int multi = 0;
int divi = 0;
bool si = true;
char signo = "";
int primer_numero = 0;
int segundo_numero = 0;
void loop() {
char c = customKeypad.getKey();
if (c){
if (c == hexaKeys[0][3]) { //SUMA
suma = 1;
signo = char("+";
}
if (c == hexaKeys[1][3]) { //RESTA
resta = 1;
signo = char("-") ;
}if (c == hexaKeys[2][3]) { //MULTIPLI
multi = 1;
signo = char("*");
}if (c == hexaKeys[3][3]) { //DIVISIO
divi = 1;
signo = char("/");
}
if (c == hexaKeys[3][2] && suma == int(1)) {
si = false;
lcd.clear();
lcd.print(primer_numero + segundo_numero);
}
if(c == hexaKeys[3][2] && resta == int(1)){
si = false;
lcd.print(primer_numero - segundo_numero);
} if (c == hexaKeys[3][2] && multi == int(1)) {
lcd.print(primer_numero * segundo_numero);
si = false;
}
if (c == hexaKeys[3][2] && divi == int(1)) {
lcd.print(primer_numero / segundo_numero);
si = false;
}
if(si == true){
a += String(c);
lcd.print(a);
Serial.println(c);
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);
}
if (c != hexaKeys[0][3] && hexaKeys[1][3] && hexaKeys[2][3] &&
hexaKeys[3][3] ){
String(primer_numero) += String(c);
if(primer_numero > 0){
String(segundo_numero) += String(c);
}
}
}
}