Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- #include <Keypad.h>
- const byte filas = 4;
- const byte columnas = 4;
- byte pinsFilas[filas]={7, 6, 5,4};//pines para filas
- byte pinsColumnas[columnas]={3, 2, A4,A5};//pines para columnas
- //Defino el Keymap
- char teclas[filas][columnas]={
- {'1','2','3','A'},
- {'4','5','6','B'},
- {'7','8','9','C'},
- {'*','0','#','D'}
- };
- Keypad teclado =Keypad(makeKeymap(teclas), pinsFilas, pinsColumnas, filas, columnas);
- //finnnnnnn
- const int rs = 12, en = 13, d4 = 11, d5 = 10, d6 = 9, d7 = 8;
- LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
- char resultado=0,operacion,variable=0,variable2=0;
- boolean primer_valor = false;
- boolean primer_operacion = false;
- boolean terminar_operacion = false;
- boolean es_negativo = false;
- void setup() {
- Serial.begin(9600);
- lcd.begin(16, 2);
- }
- void loop() {
- char boton = teclado.getKey();
- if(boton != NO_KEY){
- //*******************************SUMA*************************
- if((boton=='A')&&(primer_valor==true)&&(primer_operacion == false)){
- primer_operacion=true;
- operacion=boton;
- lcd.print ('+');
- primer_valor=false;
- }
- //*******************************RESTA
- if((boton=='B')&&(primer_valor==true)&&(primer_operacion == false)){
- primer_operacion=true;
- operacion=boton;
- lcd.print ('-');
- primer_valor=false;
- }
- //*******************************VALOR NRGATIVO
- if((boton=='B')&&(primer_valor==false)&&(primer_operacion == false)){
- es_negativo=true;
- lcd.print ('-');
- }
- //*******************************IGUAL
- if((boton =='D')){
- switch(operacion){
- case 'A':
- resultado=variable+variable2;
- if(es_negativo==true){resultado=-variable+variable2;}
- break;
- case 'B':
- resultado=variable-variable2;
- if(es_negativo==true){resultado=-variable-variable2;}
- break;
- }
- lcd.setCursor(0, 1);
- lcd.print(resultado);
- }
- //*****************************RESET******************************
- if((boton =='C')){
- lcd.clear();
- primer_valor = false;
- primer_operacion = false;
- terminar_operacion = false;
- es_negativo==false;
- resultado=0;
- variable=0;
- variable2=0;
- }
- //*****************VEO SI ES UN NUMERO*************************
- if((boton !='A')&&(boton !='B')&&(boton !='D')&&(boton !='C')){
- if(primer_operacion==false){
- primer_valor=true;
- variable=10*variable+boton-48;
- lcd.print(boton);
- primer_valor=true;
- }
- if(primer_operacion==true) {
- variable2=10*variable2+boton-48;
- lcd.print(boton);
- terminar_operacion=true;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement