![](/media/cache/group/mbed-logo-square-512_3.png.50x50_q85.png)
Additional RawSerial example
main.cpp@2:4ab47f33a1ae, 2018-01-10 (annotated)
- Committer:
- Kojto
- Date:
- Wed Jan 10 14:24:47 2018 +0000
- Revision:
- 2:4ab47f33a1ae
- Parent:
- 0:3b040f367dd8
- Child:
- 4:3ad999bfc3c4
putc instead of printf (not allowed in ISR)
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 |
Kojto | 2:4ab47f33a1ae | 10 | pc.putc(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 | } |