![](/media/cache/profiles/94bd3f4d79c60af8831740e58a68dd6e.jpg.50x50_q85.jpg)
IR control by PulseWidth.
Dependencies: IRRcevPulseWidth IRSendPulseWidth mbed
Fork of IR_LED_Send by
Diff: main.cpp
- Revision:
- 2:7e821e35909a
- Parent:
- 0:9bf7a5073dc2
diff -r 99bfec2c8ed6 -r 7e821e35909a main.cpp --- a/main.cpp Mon May 16 17:38:47 2016 +0000 +++ b/main.cpp Sun Dec 25 09:55:20 2016 +0000 @@ -1,54 +1,44 @@ #include "mbed.h" - -#define DEBOUNCEDELAY 500 +#include "IRRcevPulseWidth.h" +#include "IRSendPulseWidth.h" -// Turn ON/OFF the power of TV -int ARRAY_HIGHLOW[] = { - 2021, 971, 5512, 971, 1522, 473, 525, 473, 524, 473, 524, 473, 524, 474, 523, 474, 524, - 474, 523, 474, 525, 473, 524, 473, 524, 474, 523, 474, 524, 473, 525, 472, 524, 474, - 1521, 474, 523, 474, 524, 474, 524, 473, 524, 474, 523, 474, 523, 474, 523, 475, 523, - 474, 523, 474, 524, 473, 524, 473, 525, 473, 525, 472, 525, 473, 524, 473, 524, 473, 1522, - 474, 1521, 472, 525, 474, 1521, 474, 1521, 474, 523, 473, 1522, 473, 1522, 473, 525, 8950, - 5512, 970, 1523, 473, 524, 474, 523, 473, 526, 472, 525, 472, 525, 473, 525, 472, 525, 473, - 524, 473, 525, 472, 525, 472, 526, 472, 524, 474, 525, 472, 524, 473, 1523, 472, 525, 472, - 525, 473, 525, 472, 525, 472, 525, 473, 525, 472, 525, 472, 526, 472, 525, 472, 525, 473, 524, - 472, 526, 473, 524, 472, 526, 472, 525, 472, 525, 473, 1521, 474, 1522, 473, 524, 473, 1522, - 473, 1521, 473, 525, 473, 1522, 473, 1521, 473, 525, 8950, 5512, 971, 1522, 473, 524, 473, 525, - 473, 525, 472, 524, 473, 525, 473, 524, 473, 525, 473, 524, 473, 524, 473, 526, 471, 525, 473, - 525, 472, 526, 471, 526, 472, 1523, 472, 525, 472, 526, 471, 526, 471, 526, 472, 526, 471, 527, - 470, 527, 471, 526, 471, 527, 470, 527, 470, 527, 470, 528, 470, 527, 470, 528, 469, 528, 469, - 529, 469, 1525, 469, 1526, 469, 529, 468, 1527, 467, 1528, 467, 530, 467, 1528, 467, 1528, 467, 531,}; +#define IR_RCEV_MAX_IR_RECEV_NUM (300) +#define IR_RCEV_TIMEOUT_US (100000) -DigitalIn g_digitalinButton(P0_17); -PwmOut g_pwmoutLed(P0_13); - -void sendSignal() -{ - g_pwmoutLed.period_us( 26 ); // 38KHz => 1/38000[s] = 26.315 * 10 ^ -6 [s] = 26.315 [us] - - int iCountHighLow = sizeof( ARRAY_HIGHLOW ) / sizeof( ARRAY_HIGHLOW[0] ); - for( int iIndexHighLow = 0; iIndexHighLow < iCountHighLow; iIndexHighLow++ ) - { - g_pwmoutLed.write( 0.5 * (1 - (iIndexHighLow % 2)) ); // iIndexHighLow : even number -> 0.5, uneven number -> 0 - wait_us( ARRAY_HIGHLOW[iIndexHighLow] ); - } - g_pwmoutLed.write(0); -} +DigitalIn sw(D10,PullUp); +IRRcevPulseWidth IRrcev(D12); +IRSendPulseWidth IRsend(D11); +Serial g_serial(USBTX, USBRX); int main() { - int iButtonState_prev = 0; + uint16_t IR_RcevData[IR_RCEV_MAX_IR_RECEV_NUM]; + uint16_t i; + int8_t ret; + + IRrcev.init(IR_RcevData,IR_RCEV_MAX_IR_RECEV_NUM,IR_RCEV_TIMEOUT_US); while(1) { - int iButtonState = g_digitalinButton; - - if( 0 == iButtonState_prev && 1 == iButtonState ) + ret = IRrcev.status(); + if(ret == 1) { - sendSignal(); - wait(1); + g_serial.printf("\r\nproc succes:%d\r\nDUMP\r\n",IRrcev.getData_N()); + for(i=0;i<IRrcev.getData_N();i++) + { + g_serial.printf("%d,",IR_RcevData[i]); + } } - - iButtonState_prev = iButtonState; + else if(ret == -1) + { + g_serial.printf("\r\nCount Over!\r\n"); + } + //DD11 Low to IRsend + if(sw == 0) + { + g_serial.printf("send\r\n"); + IRsend.sendSignal(IR_RcevData,IRrcev.getData_N()); + wait(2); + } } }