x

Dependencies:   mbed ihm_L476_full

main.cpp

Committer:
gr91
Date:
2020-05-15
Revision:
0:ec600fef44bc

File content as of revision 0:ec600fef44bc:

//#include "mbed.h"
#include "ihm_L476.h"
#define PI 3.14f
Serial pc(SERIAL_TX, SERIAL_RX);
CircularBuffer <unsigned char,1024> buf;
DigitalOut led1(LED1);
DigitalOut led2(LED2);
IHM_L476 ihm;

void serial_receive()
{
    unsigned char  c=pc.getc(); // attention à protéger les appels pc
    buf.push(c);
}
//
int main()
{
    char l1,l2;
    pc.baud(9600);
    pc.printf("Hello World !\n");
    pc.attach(&serial_receive);     // isr sur reception char
    float f=10;
    int j=0;
    char str[20];
    while(1) {
        while(!buf.empty()) {
            unsigned char c;
            buf.pop(c);
            switch(c) {
                case '\r' :  // fin de message on traite
                    str[j]=NULL;  // fin de chaine
                    j=0;
                    // debut traitement chaine recue
                    sscanf(str,"%d %d %f",&l1,&l2,&f);
                    led1=l1;
                    led2=l2;
                    ihm.LCD_printf("%f",f);
                    // fin traitement chaine recue
                    break;
                case '\n':  // on ignore
                    break;
                default :   // on stocke
                    str[j]=c;
                    j++;
            }
        }
    }
}