![](/media/cache/group/mbed-logo-square-512_3.png.50x50_q85.png)
Additional RawSerial example
main.cpp@0:3b040f367dd8, 2017-01-19 (annotated)
- Committer:
- mab5449
- Date:
- Thu Jan 19 14:24:04 2017 -0600
- Revision:
- 0:3b040f367dd8
- Child:
- 2:4ab47f33a1ae
Initial commit. Ported code snippets to mbed OS 5 projects
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mab5449 | 0:3b040f367dd8 | 1 | #include "mbed.h" |
mab5449 | 0:3b040f367dd8 | 2 | |
mab5449 | 0:3b040f367dd8 | 3 | DigitalOut led1(LED1); |
mab5449 | 0:3b040f367dd8 | 4 | DigitalOut led2(LED2); |
mab5449 | 0:3b040f367dd8 | 5 | |
mab5449 | 0:3b040f367dd8 | 6 | Serial pc(USBTX, USBRX); |
mab5449 | 0:3b040f367dd8 | 7 | |
mab5449 | 0:3b040f367dd8 | 8 | void callback_ex() { |
mab5449 | 0:3b040f367dd8 | 9 | // Note: you need to actually read from the serial to clear the RX interrupt |
mab5449 | 0:3b040f367dd8 | 10 | printf("%c\n", pc.getc()); |
mab5449 | 0:3b040f367dd8 | 11 | led2 = !led2; |
mab5449 | 0:3b040f367dd8 | 12 | } |
mab5449 | 0:3b040f367dd8 | 13 | |
mab5449 | 0:3b040f367dd8 | 14 | int main() { |
mab5449 | 0:3b040f367dd8 | 15 | pc.attach(&callback_ex); |
mab5449 | 0:3b040f367dd8 | 16 | |
mab5449 | 0:3b040f367dd8 | 17 | while (1) { |
mab5449 | 0:3b040f367dd8 | 18 | led1 = !led1; |
mab5449 | 0:3b040f367dd8 | 19 | wait(0.5); |
mab5449 | 0:3b040f367dd8 | 20 | } |
mab5449 | 0:3b040f367dd8 | 21 | } |