IR control by PulseWidth.

Dependencies:   IRRcevPulseWidth IRSendPulseWidth mbed

Fork of IR_LED_Send by en 129

Files at this revision

API Documentation at this revision

Comitter:
nameless129
Date:
Sun Dec 25 09:55:20 2016 +0000
Parent:
1:99bfec2c8ed6
Commit message:
use Library

Changed in this revision

IRRcevPulseWidth.lib Show annotated file Show diff for this revision Revisions of this file
IRSendPulseWidth.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-dev.lib Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 99bfec2c8ed6 -r 7e821e35909a IRRcevPulseWidth.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IRRcevPulseWidth.lib	Sun Dec 25 09:55:20 2016 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/nameless129/code/IRRcevPulseWidth/#51aa48441784
diff -r 99bfec2c8ed6 -r 7e821e35909a IRSendPulseWidth.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IRSendPulseWidth.lib	Sun Dec 25 09:55:20 2016 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/nameless129/code/IRSendPulseWidth/#beaea9bf9c5b
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);
+        }
     }
 }
diff -r 99bfec2c8ed6 -r 7e821e35909a mbed-dev.lib
--- a/mbed-dev.lib	Mon May 16 17:38:47 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://developer.mbed.org/users/nameless129/code/mbed-dev/#2e517c56bcfb
diff -r 99bfec2c8ed6 -r 7e821e35909a mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Dec 25 09:55:20 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9baf128c2fab
\ No newline at end of file