使用红外接收库的一个demo code

Dependencies:   mbed

Fork of IR_remote by Armando Casalino

Revision:
3:29915623fbb0
Parent:
2:35f80e65a141
Child:
4:326b8df3add2
--- a/main.cpp	Thu Jul 13 11:37:43 2017 +0000
+++ b/main.cpp	Fri Jul 14 09:59:40 2017 +0000
@@ -14,39 +14,41 @@
 
 RemoteIR::Format format;
 uint8_t buf[32];
-int bitcount;
-float DC=0.5;
+int bitcount, decoded;
+double DC=0.5;
 
 int main()
 {
-    my_pwm1.period_ms(10);
+    my_pwm1.period_us(200);
     my_pwm1.write(DC);
     
-    my_pwm2.period_ms(10);
+    my_pwm2.period_us(200);
     my_pwm2.write(DC);
-    
-    
+       
 
     pc.printf("Hello World !\r\n");
     while(1) {
         
         if (ir_rx.getState() == ReceiverIR::Received) {
             bitcount = ir_rx.getData(&format, buf, sizeof(buf) * 8);
-            
-            if (bitcount>0){
+            myled=1;
+            if (bitcount>0) {
+                decoded=buf[3];
+                pc.printf("\r\nDecoded: %02X ", buf[3]);
+            }
                 
-                pc.printf("Decoded: %02X \r\n", buf[3]);
+                pc.printf(".");
                 myled = !myled;
                     
-                if (buf[3]==0xE5){
-                    DC = DC+ 0.1;
+                if (decoded==0xE5){
+                    DC = DC+ 0.01;
                     if (DC>1) DC=1;
                 }
-                if (buf[3]==0xD4){
-                    DC = DC- 0.1;
+                if (decoded==0xD4){
+                    DC = DC- 0.01;
                     if (DC<0) DC=0;
                 }    
-                if (buf[3]==0xC3){
+                if (decoded==0xC3){
                     DC = 0.5;
                 }   
                     
@@ -59,10 +61,8 @@
                      pc.printf("%02X", buf[i]);
                     }
                 */
-                
-            }
             
-        }
-
+        } else myled=0;
+        
     }
 }