IR control by PulseWidth.
Dependencies: IRRcevPulseWidth IRSendPulseWidth mbed
Fork of IR_LED_Send by
main.cpp@2:7e821e35909a, 2016-12-25 (annotated)
- Committer:
- nameless129
- Date:
- Sun Dec 25 09:55:20 2016 +0000
- Revision:
- 2:7e821e35909a
- Parent:
- 0:9bf7a5073dc2
use Library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nameless129 | 0:9bf7a5073dc2 | 1 | #include "mbed.h" |
nameless129 | 2:7e821e35909a | 2 | #include "IRRcevPulseWidth.h" |
nameless129 | 2:7e821e35909a | 3 | #include "IRSendPulseWidth.h" |
nameless129 | 0:9bf7a5073dc2 | 4 | |
nameless129 | 2:7e821e35909a | 5 | #define IR_RCEV_MAX_IR_RECEV_NUM (300) |
nameless129 | 2:7e821e35909a | 6 | #define IR_RCEV_TIMEOUT_US (100000) |
nameless129 | 0:9bf7a5073dc2 | 7 | |
nameless129 | 2:7e821e35909a | 8 | DigitalIn sw(D10,PullUp); |
nameless129 | 2:7e821e35909a | 9 | IRRcevPulseWidth IRrcev(D12); |
nameless129 | 2:7e821e35909a | 10 | IRSendPulseWidth IRsend(D11); |
nameless129 | 2:7e821e35909a | 11 | Serial g_serial(USBTX, USBRX); |
nameless129 | 0:9bf7a5073dc2 | 12 | |
nameless129 | 0:9bf7a5073dc2 | 13 | int main() |
nameless129 | 0:9bf7a5073dc2 | 14 | { |
nameless129 | 2:7e821e35909a | 15 | uint16_t IR_RcevData[IR_RCEV_MAX_IR_RECEV_NUM]; |
nameless129 | 2:7e821e35909a | 16 | uint16_t i; |
nameless129 | 2:7e821e35909a | 17 | int8_t ret; |
nameless129 | 2:7e821e35909a | 18 | |
nameless129 | 2:7e821e35909a | 19 | IRrcev.init(IR_RcevData,IR_RCEV_MAX_IR_RECEV_NUM,IR_RCEV_TIMEOUT_US); |
nameless129 | 0:9bf7a5073dc2 | 20 | |
nameless129 | 0:9bf7a5073dc2 | 21 | while(1) |
nameless129 | 0:9bf7a5073dc2 | 22 | { |
nameless129 | 2:7e821e35909a | 23 | ret = IRrcev.status(); |
nameless129 | 2:7e821e35909a | 24 | if(ret == 1) |
nameless129 | 0:9bf7a5073dc2 | 25 | { |
nameless129 | 2:7e821e35909a | 26 | g_serial.printf("\r\nproc succes:%d\r\nDUMP\r\n",IRrcev.getData_N()); |
nameless129 | 2:7e821e35909a | 27 | for(i=0;i<IRrcev.getData_N();i++) |
nameless129 | 2:7e821e35909a | 28 | { |
nameless129 | 2:7e821e35909a | 29 | g_serial.printf("%d,",IR_RcevData[i]); |
nameless129 | 2:7e821e35909a | 30 | } |
nameless129 | 0:9bf7a5073dc2 | 31 | } |
nameless129 | 2:7e821e35909a | 32 | else if(ret == -1) |
nameless129 | 2:7e821e35909a | 33 | { |
nameless129 | 2:7e821e35909a | 34 | g_serial.printf("\r\nCount Over!\r\n"); |
nameless129 | 2:7e821e35909a | 35 | } |
nameless129 | 2:7e821e35909a | 36 | //DD11 Low to IRsend |
nameless129 | 2:7e821e35909a | 37 | if(sw == 0) |
nameless129 | 2:7e821e35909a | 38 | { |
nameless129 | 2:7e821e35909a | 39 | g_serial.printf("send\r\n"); |
nameless129 | 2:7e821e35909a | 40 | IRsend.sendSignal(IR_RcevData,IRrcev.getData_N()); |
nameless129 | 2:7e821e35909a | 41 | wait(2); |
nameless129 | 2:7e821e35909a | 42 | } |
nameless129 | 0:9bf7a5073dc2 | 43 | } |
nameless129 | 0:9bf7a5073dc2 | 44 | } |