testing functionalities of serial over USB

Dependencies:   mbed

Revision:
0:8765af830f0e
Child:
1:a00097bc510b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Mar 07 14:31:11 2022 +0000
@@ -0,0 +1,33 @@
+#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;
+     
+}
\ No newline at end of file