Darley Gonzalez
/
serialarray
simple serial array test
main.cpp@1:9a0e9ef94ac6, 2015-05-28 (annotated)
- Committer:
- pedro_C
- Date:
- Thu May 28 22:58:05 2015 +0000
- Revision:
- 1:9a0e9ef94ac6
- Parent:
- 0:2786b9d7a210
serial array
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pedro_C | 0:2786b9d7a210 | 1 | #include "mbed.h" |
pedro_C | 0:2786b9d7a210 | 2 | |
pedro_C | 0:2786b9d7a210 | 3 | |
pedro_C | 0:2786b9d7a210 | 4 | |
pedro_C | 0:2786b9d7a210 | 5 | Serial pc(USBTX, USBRX); // tx, rx |
pedro_C | 0:2786b9d7a210 | 6 | |
pedro_C | 0:2786b9d7a210 | 7 | int j=0; |
pedro_C | 0:2786b9d7a210 | 8 | int x=0; |
pedro_C | 0:2786b9d7a210 | 9 | |
pedro_C | 0:2786b9d7a210 | 10 | |
pedro_C | 1:9a0e9ef94ac6 | 11 | char X_buffer []= {0,0}; //2 item array |
pedro_C | 0:2786b9d7a210 | 12 | |
pedro_C | 0:2786b9d7a210 | 13 | |
pedro_C | 0:2786b9d7a210 | 14 | |
pedro_C | 0:2786b9d7a210 | 15 | void readSerialString () |
pedro_C | 0:2786b9d7a210 | 16 | { |
pedro_C | 0:2786b9d7a210 | 17 | j=0; |
pedro_C | 0:2786b9d7a210 | 18 | while(j<=1) { |
pedro_C | 0:2786b9d7a210 | 19 | X_buffer[j] = pc.getc(); |
pedro_C | 0:2786b9d7a210 | 20 | j++; |
pedro_C | 0:2786b9d7a210 | 21 | } |
pedro_C | 0:2786b9d7a210 | 22 | |
pedro_C | 0:2786b9d7a210 | 23 | } |
pedro_C | 0:2786b9d7a210 | 24 | |
pedro_C | 0:2786b9d7a210 | 25 | |
pedro_C | 0:2786b9d7a210 | 26 | int main() |
pedro_C | 0:2786b9d7a210 | 27 | |
pedro_C | 0:2786b9d7a210 | 28 | { |
pedro_C | 0:2786b9d7a210 | 29 | pc.baud(115200); |
pedro_C | 0:2786b9d7a210 | 30 | |
pedro_C | 0:2786b9d7a210 | 31 | while(1) { |
pedro_C | 0:2786b9d7a210 | 32 | readSerialString (); |
pedro_C | 0:2786b9d7a210 | 33 | |
pedro_C | 0:2786b9d7a210 | 34 | |
pedro_C | 1:9a0e9ef94ac6 | 35 | x=atoi(X_buffer); //convert to int |
pedro_C | 0:2786b9d7a210 | 36 | |
pedro_C | 0:2786b9d7a210 | 37 | pc.printf("%d\n",x); |
pedro_C | 0:2786b9d7a210 | 38 | |
pedro_C | 0:2786b9d7a210 | 39 | } |
pedro_C | 0:2786b9d7a210 | 40 | } |