testing functionalities of serial over USB

Dependencies:   mbed

main.cpp

Committer:
ffxx68
Date:
2022-03-07
Revision:
0:8765af830f0e
Child:
1:a00097bc510b

File content as of revision 0:8765af830f0e:

#include "mbed.h"

DigitalOut myled(LED1);
Serial pc(USBTX,USBRX); 

int main()
{
 
    pc.baud(9600); //  8 bit No parity 1 stop
    int i = 0;
    char inChar;
    //PC.printf("\nPress Button to enter/exit sleep & deepsleep\n");
    
    // main loop
    while( true ) {
        
        // wait for something on input
        while ( !pc.readable() ) {
            myled = !myled;
            wait(.5)
        }
        myled = 1; 
        
        fflush(stdout);
        inChar=pc.getc(); // get char over serial
        pc.printf ("0x%.2X", inChar); // echo HEX code
        if ( inChar = '\r' ) pc.putc('\n');  // add a line feed on return
     
    } 
     
    myled = 0;
     
}