![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
1
main.cpp@0:0befb1dbf37e, 2021-03-09 (annotated)
- Committer:
- sunghunKim
- Date:
- Tue Mar 09 17:03:19 2021 +0000
- Revision:
- 0:0befb1dbf37e
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sunghunKim | 0:0befb1dbf37e | 1 | #include "mbed.h" |
sunghunKim | 0:0befb1dbf37e | 2 | Serial pc(USBTX, USBRX); |
sunghunKim | 0:0befb1dbf37e | 3 | Serial device(p13, p14); // tx, rx |
sunghunKim | 0:0befb1dbf37e | 4 | DigitalOut myled(LED1); |
sunghunKim | 0:0befb1dbf37e | 5 | void onSerialRx() { |
sunghunKim | 0:0befb1dbf37e | 6 | |
sunghunKim | 0:0befb1dbf37e | 7 | static char serialInBuffer[2]; |
sunghunKim | 0:0befb1dbf37e | 8 | static int serialCount = -1; |
sunghunKim | 0:0befb1dbf37e | 9 | |
sunghunKim | 0:0befb1dbf37e | 10 | |
sunghunKim | 0:0befb1dbf37e | 11 | while (device.readable()) { // in case two bytes are ready |
sunghunKim | 0:0befb1dbf37e | 12 | char byteIn = device.getc(); |
sunghunKim | 0:0befb1dbf37e | 13 | pc.printf("%c", byteIn); |
sunghunKim | 0:0befb1dbf37e | 14 | } |
sunghunKim | 0:0befb1dbf37e | 15 | |
sunghunKim | 0:0befb1dbf37e | 16 | } |
sunghunKim | 0:0befb1dbf37e | 17 | int main() { |
sunghunKim | 0:0befb1dbf37e | 18 | device.baud(9600); |
sunghunKim | 0:0befb1dbf37e | 19 | device.attach(&onSerialRx); |
sunghunKim | 0:0befb1dbf37e | 20 | while(1) { |
sunghunKim | 0:0befb1dbf37e | 21 | myled = 1; |
sunghunKim | 0:0befb1dbf37e | 22 | wait(0.2); |
sunghunKim | 0:0befb1dbf37e | 23 | myled = 0; |
sunghunKim | 0:0befb1dbf37e | 24 | wait(0.2); |
sunghunKim | 0:0befb1dbf37e | 25 | //pc.printf("pc2"); |
sunghunKim | 0:0befb1dbf37e | 26 | device.printf("test"); |
sunghunKim | 0:0befb1dbf37e | 27 | |
sunghunKim | 0:0befb1dbf37e | 28 | } |
sunghunKim | 0:0befb1dbf37e | 29 | } |