TaChing Yu
/
Serial_2
main.cpp@0:5d2615cbb0df, 2016-08-27 (annotated)
- Committer:
- yu10078999
- Date:
- Sat Aug 27 11:22:23 2016 +0000
- Revision:
- 0:5d2615cbb0df
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yu10078999 | 0:5d2615cbb0df | 1 | #include "mbed.h" |
yu10078999 | 0:5d2615cbb0df | 2 | DigitalOut led(D2); |
yu10078999 | 0:5d2615cbb0df | 3 | Serial pc(USBTX, USBRX); |
yu10078999 | 0:5d2615cbb0df | 4 | char val; |
yu10078999 | 0:5d2615cbb0df | 5 | int main() { |
yu10078999 | 0:5d2615cbb0df | 6 | pc.baud(9600); |
yu10078999 | 0:5d2615cbb0df | 7 | while(1) { |
yu10078999 | 0:5d2615cbb0df | 8 | if(pc.readable()) { |
yu10078999 | 0:5d2615cbb0df | 9 | pc.printf("Ready\n"); |
yu10078999 | 0:5d2615cbb0df | 10 | val = pc.getc(); |
yu10078999 | 0:5d2615cbb0df | 11 | if(val=='a'){ |
yu10078999 | 0:5d2615cbb0df | 12 | led = 1 ; |
yu10078999 | 0:5d2615cbb0df | 13 | pc.printf("LED ON\n"); |
yu10078999 | 0:5d2615cbb0df | 14 | } |
yu10078999 | 0:5d2615cbb0df | 15 | else if (val == 'b') { |
yu10078999 | 0:5d2615cbb0df | 16 | led = 0; |
yu10078999 | 0:5d2615cbb0df | 17 | pc.printf("LED OFF\n"); |
yu10078999 | 0:5d2615cbb0df | 18 | } |
yu10078999 | 0:5d2615cbb0df | 19 | } |
yu10078999 | 0:5d2615cbb0df | 20 | } |
yu10078999 | 0:5d2615cbb0df | 21 | } |