Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

/*

Prueba }

*/

#include <stdlib.h>

#include <Keypad.h>

#include <LiquidCrystal.h>//librerá de pantalla lcd

LiquidCrystal LCD(12, 13, 19, 18, 17, 16); //pines de habilitacion RS,E,D4,D5,D6,D7

int i = 0;

int j = 0;

int suma ;

int resta ;

int divi;

int multi;

int compb1;

int compb2;

int oper;

int op1;

const byte ROWS = 4; //four rows

const byte COLS = 4; //four columns

//define the cymbols on the buttons of the keypads

char tecla1[1] = {'1'}; //Caracteres en la tecla 1

int t1 = 0; //variable para contador

char tecla2 [1] = {'2'}; //Caracteres en la tecla 2

int t2 = 0; //variable para contador

char tecla3 [1] = {'3'}; //Caracteres en la tecla 3

int t3 = 0; //variable para contador

char tecla4 [1] = {'4'}; //Caracteres en la tecla 4

int t4 = 0; //variable para contador

char tecla5 [1] = {'5'}; //Caracteres en la tecla 5

int t5 = 0; //variable para contador


char tecla6 [1] = {'6'}; //Caracteres en la tecla 6

int t6 = 0; //variable para contador

char tecla7 [1] = {'7'}; //Caracteres en la tecla 7

int t7 = 0; //variable para contador

char tecla8 [1] = {'8'}; //Caracteres en la tecla 8

int t8 = 0; //variable para contador

char tecla9 [1] = {'9'}; //Caracteres en la tecla 8

int t9 = 0; //variable para contador

char hexaKeys[ROWS][COLS] = {

{'7', '8', '9', '/'},

{'4', '5', '6', '*'},

{'1', '2', '3', '-'},

{'O', '0', '=', '+'}

};

byte rowPins[ROWS] = {4, 5, 6 , 7 }; //connect to the row pinouts of the keypad

byte colPins[COLS] = {8, 9, 10, 11}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad

Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

char ingreso1[2] = {};

char ingreso2[2] = {};

char operacion[3] = {};

char aux[2] = {};

void teclado1(char vect[], char


customKey)////*////////////////////////////////////////////////////////////////////////////////////////
/////////////////

{ if (i < 2)

vect[i] = customKey;

Serial.print(customKey);
i++;

compb1 = 1;

else {

i = 0;

compb1 = 0;

void teclado2(char vect[], char


customKey)////*////////////////////////////////////////////////////////////////////////////////////////
/////////////////

{ if (j < 2)

vect[j] = customKey;

Serial.print(customKey);

j++;

compb2 = 1;

else {

j = 0;

compb2 = 0;

void llenarvector(char vector1[], char vector2[]) {

for (int j = 0; j < 2; j++) {

vector1[j] = vector2[j];

void setup()
{//*//////////////////////////////////////////////////////////////////////////////////////////////////////
///
LCD.begin(16, 2); //inicializar lcd

Serial.begin(9600);

LCD.clear();

void loop() {
//********************************************************************************
******

char customKey = customKeypad.getKey();

// if (customKey) {

switch (customKey) {

case '1':

{ teclado1(ingreso1, customKey);

LCD.setCursor(0, 1 );

LCD.print(ingreso1);

break;

case '2':

{ teclado1(ingreso1, customKey);

LCD.setCursor(0, 1 );

LCD.print(ingreso1);

break;

case '3':

{ teclado1(ingreso1, customKey);

LCD.setCursor(0, 1 );

LCD.print(ingreso1);

break;

case '4':

{ teclado1(ingreso1, customKey);
LCD.setCursor(0, 1 );

LCD.print(ingreso1);

break;

case '5':

{ teclado1(ingreso1, customKey);

LCD.setCursor(0, 1 );

LCD.print(ingreso1);

break;

case '6':

{ teclado1(ingreso1, customKey);

LCD.setCursor(0, 1 );

LCD.print(ingreso1);

break;

case '7':

{ teclado1(ingreso1, customKey);

LCD.setCursor(0, 1 );

LCD.print(ingreso1);

break;

case '8':

{ teclado1(ingreso1, customKey);

LCD.setCursor(0, 1 );

LCD.print(ingreso1);

break;

case '9':

{ teclado1(ingreso1, customKey);

LCD.setCursor(0, 1 );
LCD.print(ingreso1);

break;

case '0':

{ teclado1(ingreso1, customKey);

LCD.setCursor(0, 1 );

LCD.print(ingreso1);

break;

case '=':

{ switch (oper)

case 1:

suma=atoi(ingreso1) + atoi(aux);

LCD.setCursor(0, 1);

LCD.print(suma);

break;

case 2:

{ resta = atoi(ingreso1) - atoi(aux); //+atoi(ingreso2);

LCD.setCursor(0, 1);

LCD.print('=');

LCD.setCursor(0, 2);

LCD.print(resta);

break;

case 3:

{ multi = atoi(ingreso1) * atoi(aux); //+atoi(ingreso2);


LCD.setCursor(0, 1);

LCD.print('=');

LCD.setCursor(0, 2);

LCD.print(multi);

break;

case 4:

{ divi = atoi(ingreso1) / atoi(aux); //+atoi(ingreso2);

LCD.setCursor(0, 1);

LCD.print('=');

LCD.setCursor(0, 2);

LCD.print(divi);

break;

break;

case '+':

{ oper = 1;

if (compb1 = 1)

{ llenarvector(aux, ingreso1);

LCD.setCursor(0, 1);

LCD.print(" ");

} else

LCD.clear();

LCD.setCursor(0, 1);

LCD.print("SYNTAX ERROR");

break;
case '-':

{ oper = 2;

if (compb1 = 1)

{ llenarvector(aux, ingreso1);

LCD.setCursor(0, 1);

LCD.print(" ");

} else

LCD.clear();

LCD.setCursor(0, 1);

LCD.print("SYNTAX ERROR");

ingreso1[2] = "";

break;

case '*':

{ oper = 3;

if (compb1 = 1)

{ llenarvector(aux, ingreso1);

LCD.setCursor(0, 1);

LCD.print(" ");

} else

LCD.clear();

LCD.setCursor(0, 1);

LCD.print("SYNTAX ERROR");

ingreso1[2] = "";

break;

case '/':
{ oper = 4;

if (compb1 = 1)

{ llenarvector(aux, ingreso1);

LCD.setCursor(0, 1);

LCD.print(" ");

} else

LCD.clear();

LCD.setCursor(0, 1);

LCD.print("SYNTAX ERROR");

ingreso1[2] = "";

break;

case 'O':

LCD.clear();

LCD.setCursor(0, 0);

LCD.print("ON");

break;

You might also like