Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // C++ code
- //
- #include <Keypad.h>
- const byte FILAS = 4; //Cantidad de filas
- const byte COLS = 4; //Cantidad de columnas
- //Matriz de valores
- char teclas[FILAS][COLS] = {
- {'1','2','3','+'},
- {'4','5','6','-'},
- {'7','8','9','*'},
- {'*','0','=','/'},
- };
- //Configuración de conexión
- byte PinFila[FILAS] = {9,8,7,6};//conexión de filas
- byte PinCols[COLS] = {5,4,3,2};//conexión de columnas
- //Crear objeto de la clase Keypad
- Keypad teclado = Keypad(makeKeymap(teclas), PinFila, PinCols, FILAS, COLS);
- int paso =0;
- int numero1=0;
- int numero2=0;
- int operacion=0;
- int resultado=0;
- int r=0;
- void setup()
- {
- Serial.begin(9600);
- Serial.println();
- }
- void loop()
- {
- if(paso==0){
- Serial.println();
- Serial.print("primer numero:");
- paso++;
- }
- if(paso==1){
- char tecla = teclado.getKey();
- if (tecla != 0x00)
- {
- Serial.print(tecla);
- numero1 = String(tecla).toInt();
- paso++;
- }
- }
- if(paso==2){
- Serial.println();
- Serial.print("Operador:");
- paso++;
- }
- if(paso==3){
- char tecla = teclado.getKey();
- if (tecla != 0x00)
- {
- Serial.print(tecla);
- operacion = tecla;
- paso++;
- }
- }
- if(paso==4){
- Serial.println();
- Serial.print("segundo numero:");
- paso++;
- }
- if(paso==5){
- char tecla = teclado.getKey();
- if (tecla != 0x00)
- {
- Serial.print(tecla);
- numero2 = String(tecla).toInt();
- paso++;
- }
- }
- if(paso==6){
- Serial.println();
- Serial.print("Resultado:");
- if(operacion=='+')
- {
- resultado=numero1+numero2;
- }
- if(operacion=='-')
- {
- resultado=numero1-numero2;
- }
- if(operacion=='*')
- {
- resultado=numero1*numero2;
- }
- if(operacion=='/')
- {
- if(numero2!=0)
- {
- resultado=numero1/numero2;
- }
- else{
- Serial.println("Infinito");
- }
- }
- Serial.println(resultado);
- paso =0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement