sergio restrepo
/
Serial
ejemplo serial
main.cpp@0:e96c74fb13c2, 2019-10-07 (annotated)
- Committer:
- sergio_restrepo
- Date:
- Mon Oct 07 23:30:09 2019 +0000
- Revision:
- 0:e96c74fb13c2
serial_ejemplo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sergio_restrepo | 0:e96c74fb13c2 | 1 | #include "mbed.h" |
sergio_restrepo | 0:e96c74fb13c2 | 2 | |
sergio_restrepo | 0:e96c74fb13c2 | 3 | Serial pc(USBTX, USBRX); // tx, rx |
sergio_restrepo | 0:e96c74fb13c2 | 4 | int i = 0; |
sergio_restrepo | 0:e96c74fb13c2 | 5 | char c; |
sergio_restrepo | 0:e96c74fb13c2 | 6 | |
sergio_restrepo | 0:e96c74fb13c2 | 7 | int main() { |
sergio_restrepo | 0:e96c74fb13c2 | 8 | pc.printf("Ingrese 1 para iniciar\nIngrese p para detener\n"); |
sergio_restrepo | 0:e96c74fb13c2 | 9 | c = pc.getc(); |
sergio_restrepo | 0:e96c74fb13c2 | 10 | while(1) { |
sergio_restrepo | 0:e96c74fb13c2 | 11 | if(c == '1'){ |
sergio_restrepo | 0:e96c74fb13c2 | 12 | pc.printf("%d\n",i); |
sergio_restrepo | 0:e96c74fb13c2 | 13 | i++; |
sergio_restrepo | 0:e96c74fb13c2 | 14 | wait(1); |
sergio_restrepo | 0:e96c74fb13c2 | 15 | if(pc.readable()){ |
sergio_restrepo | 0:e96c74fb13c2 | 16 | if (pc.getc()=='p'){ |
sergio_restrepo | 0:e96c74fb13c2 | 17 | return 0; |
sergio_restrepo | 0:e96c74fb13c2 | 18 | } |
sergio_restrepo | 0:e96c74fb13c2 | 19 | } |
sergio_restrepo | 0:e96c74fb13c2 | 20 | } |
sergio_restrepo | 0:e96c74fb13c2 | 21 | else{ |
sergio_restrepo | 0:e96c74fb13c2 | 22 | pc.printf("Error - Ingrese 1 para iniciar\n"); |
sergio_restrepo | 0:e96c74fb13c2 | 23 | c = pc.getc(); |
sergio_restrepo | 0:e96c74fb13c2 | 24 | } |
sergio_restrepo | 0:e96c74fb13c2 | 25 | } |
sergio_restrepo | 0:e96c74fb13c2 | 26 | } |