PEDRO MATIZ
/
CHATSERIAL
CHAT SERIAL
main.cpp@0:6f1384d9a913, 2017-09-30 (annotated)
- Committer:
- ABD931
- Date:
- Sat Sep 30 21:03:52 2017 +0000
- Revision:
- 0:6f1384d9a913
PROGRAMA DE CHAT SERIAL
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ABD931 | 0:6f1384d9a913 | 1 | //CODIGO PAR EL CHAT SERIAL |
ABD931 | 0:6f1384d9a913 | 2 | |
ABD931 | 0:6f1384d9a913 | 3 | #include "mbed.h" |
ABD931 | 0:6f1384d9a913 | 4 | #include "SoftSerial.h" |
ABD931 | 0:6f1384d9a913 | 5 | #include <string> |
ABD931 | 0:6f1384d9a913 | 6 | /******************************************************************************/ |
ABD931 | 0:6f1384d9a913 | 7 | char c; |
ABD931 | 0:6f1384d9a913 | 8 | SoftSerial con(D4,D5);//tx.rx |
ABD931 | 0:6f1384d9a913 | 9 | Serial pc(USBTX,USBRX); |
ABD931 | 0:6f1384d9a913 | 10 | |
ABD931 | 0:6f1384d9a913 | 11 | /******************************************************************************/ |
ABD931 | 0:6f1384d9a913 | 12 | |
ABD931 | 0:6f1384d9a913 | 13 | |
ABD931 | 0:6f1384d9a913 | 14 | int main (){ |
ABD931 | 0:6f1384d9a913 | 15 | //AnalogIn ai(A0); |
ABD931 | 0:6f1384d9a913 | 16 | //lcd.locate(0,0); |
ABD931 | 0:6f1384d9a913 | 17 | //wait(0.1); |
ABD931 | 0:6f1384d9a913 | 18 | //lcd.locate(0,0); |
ABD931 | 0:6f1384d9a913 | 19 | con.baud(9600); |
ABD931 | 0:6f1384d9a913 | 20 | pc.baud(9600); |
ABD931 | 0:6f1384d9a913 | 21 | |
ABD931 | 0:6f1384d9a913 | 22 | wait(0.1); |
ABD931 | 0:6f1384d9a913 | 23 | |
ABD931 | 0:6f1384d9a913 | 24 | //lcd.cls(); |
ABD931 | 0:6f1384d9a913 | 25 | while (1) |
ABD931 | 0:6f1384d9a913 | 26 | { |
ABD931 | 0:6f1384d9a913 | 27 | while (pc.readable()>0) |
ABD931 | 0:6f1384d9a913 | 28 | { |
ABD931 | 0:6f1384d9a913 | 29 | con.putc(pc.getc()); |
ABD931 | 0:6f1384d9a913 | 30 | |
ABD931 | 0:6f1384d9a913 | 31 | } |
ABD931 | 0:6f1384d9a913 | 32 | |
ABD931 | 0:6f1384d9a913 | 33 | while (con.readable()>0) |
ABD931 | 0:6f1384d9a913 | 34 | { |
ABD931 | 0:6f1384d9a913 | 35 | pc.putc(con.getc()); |
ABD931 | 0:6f1384d9a913 | 36 | //lcd.printf("%s",readString); |
ABD931 | 0:6f1384d9a913 | 37 | } |
ABD931 | 0:6f1384d9a913 | 38 | wait(0.01); |
ABD931 | 0:6f1384d9a913 | 39 | |
ABD931 | 0:6f1384d9a913 | 40 | if (con.readable()>0) |
ABD931 | 0:6f1384d9a913 | 41 | { |
ABD931 | 0:6f1384d9a913 | 42 | c=con.getc(); |
ABD931 | 0:6f1384d9a913 | 43 | |
ABD931 | 0:6f1384d9a913 | 44 | pc.printf("%c",c); |
ABD931 | 0:6f1384d9a913 | 45 | //lcd.printf("%s",readString); |
ABD931 | 0:6f1384d9a913 | 46 | wait(0.5); |
ABD931 | 0:6f1384d9a913 | 47 | } |
ABD931 | 0:6f1384d9a913 | 48 | |
ABD931 | 0:6f1384d9a913 | 49 | } |
ABD931 | 0:6f1384d9a913 | 50 | } |