Calculadora por puerto serial, coolterm.

Dependencies:   mbed

main.cpp

Committer:
jiuk
Date:
2018-08-17
Revision:
0:fb219645728a

File content as of revision 0:fb219645728a:

#include "mbed.h"
#define DEBUG 1

Serial pc(SERIAL_TX, SERIAL_RX);

void mdebug(char *s){
    #if DEBUG
        pc.printf(s);
    #endif
    }

void f_p(int N){
    pc.printf("La resuesta es: %d ", N );
    //char c=N/100;
    //char d=(N/10) -(c*10/10);
    //char u=N-c*100-d*10;
    //pc.putc(c);pc.putc(d);pc.putc(u);
    //pc.printf("%d, %d, %d",c,d,u);
    }

int main()
{
    pc.baud(9600); //velocidad de funcionamiento
    void f_p(int N);
    char op1;
    char op2;
    char tp;
    int rst;
    while(1) {
        //pc.printf("Press '1' to turn LED1 ON, '0' to turn it OFF \r\n");
        mdebug("\nIngrese dato 1: \n");
        op1=pc.getc();
        printf("%d ",op1);
        mdebug("Ingrese dato 2: \n");
        op2=pc.getc();
        mdebug("Ingrese el operador: \n");
        //mdebug("1=mul 2=div 3=sum 4=res ");
        tp=pc.getc();
        //printf("op1=%d,op2=%d",op1,op2);
        switch (tp){
            case 1:rst=op1*op2;
            break;
            case 2:rst=op1/op2;
            break;
            case 3:rst=op1+op2;
            break;
            case 4:rst=op1-op2;
            break;
            default:rst='E';
            break;
            }
        f_p(rst);
    }
}