Seongbin Lim
/
sb_first_project
This is a very simple guide, reviewing the steps required to get Blinky working on an Mbed OS platform.
main.cpp
- Committer:
- sb8718
- Date:
- 2020-05-08
- Revision:
- 131:8fb226cc407c
- Parent:
- 130:d19783810c05
- Child:
- 132:e36000d354c6
- Child:
- 134:139f37fecf3d
File content as of revision 131:8fb226cc407c:
#include "mbed.h" #include "ReceiverIR.h" Serial pc(PA_2, PA_3, 115200); //IR receiver D4 ReceiverIR ir_rx(D3); void display_data(uint8_t *buf, int bitlength) { const int n = bitlength / 8 + (((bitlength % 8) != 0) ? 1 : 0); for (int i = 0; i < n; i++) { pc.printf("%02X", buf[i]); } for (int i = 0; i < 8 - n; i++) { pc.printf("--"); } } int receive(RemoteIR::Format *format, uint8_t *buf, int bufsiz, int timeout = 100) { int cnt = 0; while (ir_rx.getState() != ReceiverIR::Received) { cnt++; if (timeout < cnt) { return -1; } } return ir_rx.getData(format, buf, bufsiz * 8); } int main() { pc.printf("\r\n\r\n\r\n\r\nStart!!\r\n"); while (1) { RemoteIR::Format format; uint8_t buf[32]; int bitcount; if (ir_rx.getState() == ReceiverIR::Received) { bitcount = ir_rx.getData(&format, buf, sizeof(buf)); } bitcount = receive(&format, buf, sizeof(buf)); if (bitcount < 0) { continue; } display_data(buf, bitcount); } }