sample of getting console key
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.
main.cpp@0:06c67ac20cd3, 2016-04-09 (annotated)
- Committer:
- okano
- Date:
- Sat Apr 09 08:08:16 2016 +0000
- Revision:
- 0:06c67ac20cd3
initial version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okano | 0:06c67ac20cd3 | 1 | #include "mbed.h" |
okano | 0:06c67ac20cd3 | 2 | |
okano | 0:06c67ac20cd3 | 3 | Serial pc( USBTX, USBRX ); |
okano | 0:06c67ac20cd3 | 4 | BusOut leds( LED4, LED3, LED2, LED1 ); |
okano | 0:06c67ac20cd3 | 5 | |
okano | 0:06c67ac20cd3 | 6 | int main() |
okano | 0:06c67ac20cd3 | 7 | { |
okano | 0:06c67ac20cd3 | 8 | while (1) { |
okano | 0:06c67ac20cd3 | 9 | if ( pc.readable() ) { |
okano | 0:06c67ac20cd3 | 10 | leds = pc.getc() - '0'; |
okano | 0:06c67ac20cd3 | 11 | } |
okano | 0:06c67ac20cd3 | 12 | } |
okano | 0:06c67ac20cd3 | 13 | } |