sample of getting console key

Dependencies:   mbed

Sample code of how to get key hit.
readable() function in Serial class can check buffer has data or not.

This could be equivalent to kbhit() function of DOS/Win environment.

Files at this revision

API Documentation at this revision

Comitter:
okano
Date:
Sat Apr 09 08:08:16 2016 +0000
Commit message:
initial version

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 06c67ac20cd3 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Apr 09 08:08:16 2016 +0000
@@ -0,0 +1,13 @@
+#include "mbed.h"
+
+Serial  pc( USBTX, USBRX );
+BusOut  leds( LED4, LED3, LED2, LED1 );
+
+int main()
+{
+    while (1) {
+        if ( pc.readable() ) {
+            leds    = pc.getc() - '0';
+        }
+    }
+}
diff -r 000000000000 -r 06c67ac20cd3 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Apr 09 08:08:16 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/99a22ba036c9
\ No newline at end of file