Dr. Pucher
/
Serial_interrupts
Test
main.cpp@2:f026b40fadb1, 2018-11-15 (annotated)
- Committer:
- bulmecisco
- Date:
- Thu Nov 15 17:10:45 2018 +0000
- Revision:
- 2:f026b40fadb1
- Parent:
- 0:023c5cda6102
Test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bulmecisco | 2:f026b40fadb1 | 1 | #include "mbed.h" |
4180_1 | 0:023c5cda6102 | 2 | |
4180_1 | 0:023c5cda6102 | 3 | DigitalOut led1(LED1); |
4180_1 | 0:023c5cda6102 | 4 | DigitalOut led2(LED2); |
4180_1 | 0:023c5cda6102 | 5 | |
bulmecisco | 2:f026b40fadb1 | 6 | Serial pc(USBTX, USBRX); |
4180_1 | 0:023c5cda6102 | 7 | |
bulmecisco | 2:f026b40fadb1 | 8 | bool flag = false; |
bulmecisco | 2:f026b40fadb1 | 9 | char rec; |
4180_1 | 0:023c5cda6102 | 10 | |
bulmecisco | 2:f026b40fadb1 | 11 | void callback_ex() { |
bulmecisco | 2:f026b40fadb1 | 12 | // Note: you need to actually read from the serial to clear the RX interrupt |
bulmecisco | 2:f026b40fadb1 | 13 | //pc.putc(pc.getc()); |
bulmecisco | 2:f026b40fadb1 | 14 | while(pc.readable()) { |
bulmecisco | 2:f026b40fadb1 | 15 | rec = pc.getc(); |
4180_1 | 0:023c5cda6102 | 16 | } |
bulmecisco | 2:f026b40fadb1 | 17 | flag = true; |
bulmecisco | 2:f026b40fadb1 | 18 | led2 = !led2; |
4180_1 | 0:023c5cda6102 | 19 | } |
4180_1 | 0:023c5cda6102 | 20 | |
bulmecisco | 2:f026b40fadb1 | 21 | int main() { |
bulmecisco | 2:f026b40fadb1 | 22 | pc.attach(&callback_ex); |
bulmecisco | 2:f026b40fadb1 | 23 | |
bulmecisco | 2:f026b40fadb1 | 24 | while (1) { |
bulmecisco | 2:f026b40fadb1 | 25 | led1 = !led1; |
bulmecisco | 2:f026b40fadb1 | 26 | // wait(0.5); |
bulmecisco | 2:f026b40fadb1 | 27 | if(flag) { |
bulmecisco | 2:f026b40fadb1 | 28 | pc.putc(rec); |
bulmecisco | 2:f026b40fadb1 | 29 | flag = false; |
bulmecisco | 2:f026b40fadb1 | 30 | // led1 = !led1; |
bulmecisco | 2:f026b40fadb1 | 31 | } |
4180_1 | 0:023c5cda6102 | 32 | } |
4180_1 | 0:023c5cda6102 | 33 | } |