Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- yuki
- Date:
- 2014-08-09
- Revision:
- 0:7c39876eb334
- Child:
- 1:4e6dc3e5ab7c
File content as of revision 0:7c39876eb334:
#include "mbed.h"
#include "ReceiverIR.h"
DigitalOut myled1(dp28); // MARY GREEN LED
DigitalOut myled2(dp14); // MARY BLUE LED
DigitalOut myled3(xp12);
ReceiverIR ir_rx(dp17);
//TX dp16 = USBTX RX dp15 = USBRX
Serial pc(USBTX, USBRX);
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.baud(9600);
RemoteIR::Format format;
uint8_t buf[64];
int bufLength = 0;
myled1 = myled2 = myled3 = 1;
while(1) {
myled1 = 0;
memset(buf, 0x00, sizeof(buf));
bufLength = receive(&format, buf, sizeof(buf));
if(bufLength < 0) continue;
myled1 = 1;
myled2 = 0;
const int n = bufLength / 8 + (((bufLength % 8) != 0) ? 1 : 0);
for (int i = 0; i < n; i++) {
pc.printf("%02X", buf[i]);
}
pc.printf(" %d ", bufLength);
switch (format) {
case RemoteIR::UNKNOWN:
pc.printf("UNKNOWN");
myled2 = 1;
myled3 = 0;
break;
case RemoteIR::NEC:
pc.printf("NEC");
break;
case RemoteIR::NEC_REPEAT:
pc.printf("NEC(R)");
break;
case RemoteIR::AEHA:
pc.printf("AEHA");
break;
case RemoteIR::AEHA_REPEAT:
pc.printf("AEHA(R)");
break;
case RemoteIR::SONY:
pc.printf("SONY");
break;
}
pc.printf(" OK\r\n");
wait_ms(450);
myled2 = 1;
myled3 = 1;
wait_ms(150);
}
}