Armando Casalino
/
IR_remote
A test script for testing a generic IR remote on STM32 NUCLEO
main.cpp@1:5e7be7addf96, 2017-07-13 (annotated)
- Committer:
- havebug
- Date:
- Thu Jul 13 08:07:25 2017 +0000
- Revision:
- 1:5e7be7addf96
- Parent:
- 0:42764550a2cb
- Child:
- 2:35f80e65a141
Led switch on single received press;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
havebug | 0:42764550a2cb | 1 | #include "mbed.h" |
havebug | 0:42764550a2cb | 2 | #include "ReceiverIR.h" |
havebug | 0:42764550a2cb | 3 | ReceiverIR ir_rx(D2); |
havebug | 0:42764550a2cb | 4 | |
havebug | 0:42764550a2cb | 5 | Serial pc(SERIAL_TX, SERIAL_RX); |
havebug | 0:42764550a2cb | 6 | DigitalOut myled(LED1); |
havebug | 0:42764550a2cb | 7 | |
havebug | 0:42764550a2cb | 8 | RemoteIR::Format format; |
havebug | 0:42764550a2cb | 9 | uint8_t buf[32]; |
havebug | 0:42764550a2cb | 10 | int bitcount; |
havebug | 0:42764550a2cb | 11 | |
havebug | 0:42764550a2cb | 12 | int main() |
havebug | 0:42764550a2cb | 13 | { |
havebug | 0:42764550a2cb | 14 | |
havebug | 0:42764550a2cb | 15 | pc.printf("Hello World !\r\n"); |
havebug | 0:42764550a2cb | 16 | while(1) { |
havebug | 0:42764550a2cb | 17 | |
havebug | 0:42764550a2cb | 18 | if (ir_rx.getState() == ReceiverIR::Received) { |
havebug | 0:42764550a2cb | 19 | bitcount = ir_rx.getData(&format, buf, sizeof(buf) * 8); |
havebug | 0:42764550a2cb | 20 | |
havebug | 0:42764550a2cb | 21 | if (bitcount>0){ |
havebug | 0:42764550a2cb | 22 | |
havebug | 0:42764550a2cb | 23 | pc.printf("Decoded: %02X \r\n", buf[3]); |
havebug | 0:42764550a2cb | 24 | myled = !myled; |
havebug | 0:42764550a2cb | 25 | |
havebug | 0:42764550a2cb | 26 | /* DEBUG |
havebug | 0:42764550a2cb | 27 | for (int i = 0; i < bitcount; i++) { |
havebug | 0:42764550a2cb | 28 | pc.printf("%02X", buf[i]); |
havebug | 0:42764550a2cb | 29 | } |
havebug | 0:42764550a2cb | 30 | */ |
havebug | 0:42764550a2cb | 31 | |
havebug | 0:42764550a2cb | 32 | } |
havebug | 0:42764550a2cb | 33 | |
havebug | 0:42764550a2cb | 34 | } |
havebug | 0:42764550a2cb | 35 | |
havebug | 0:42764550a2cb | 36 | } |
havebug | 0:42764550a2cb | 37 | } |