chen ada
/
IR_remote_demo_code
使用红外接收库的一个demo code
Fork of IR_remote by
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "ReceiverIR.h" 00003 00004 DigitalOut my_led(LED1); 00005 00006 //PwmOut my_pwm1(PB_3); 00007 //PwmOut my_pwm2(PB_5); 00008 00009 00010 ReceiverIR ir_rx(PA_12); 00011 00012 Serial pc(SERIAL_TX, SERIAL_RX); 00013 DigitalOut myled(LED1); 00014 00015 RemoteIR::Format format; 00016 uint8_t buf[32]; 00017 int bitcount, decoded; 00018 double DC=0.5; 00019 00020 int main() 00021 { 00022 //my_pwm1.period_us(200); 00023 //my_pwm1.write(DC); 00024 00025 //my_pwm2.period_us(200); 00026 //my_pwm2.write(DC); 00027 00028 00029 pc.printf("Hello World !\r\n"); 00030 while(1) { 00031 00032 if (ir_rx.getState() == ReceiverIR::Received) { 00033 bitcount = ir_rx.getData(&format, buf, sizeof(buf) * 8); 00034 myled=1; 00035 if (bitcount>0) { 00036 decoded=buf[3]; 00037 pc.printf("\r\nDecoded: %x ", buf[0]); 00038 pc.printf("\r\nDecoded: %x ", buf[1]); 00039 pc.printf("\r\nDecoded: %x ", buf[2]); 00040 pc.printf("\r\nDecoded: %x ", buf[3]); 00041 } 00042 00043 pc.printf("."); 00044 myled = !myled; 00045 00046 //if (decoded==0xE5){ 00047 // DC = DC+ 0.01; 00048 // if (DC>1) DC=1; 00049 //} 00050 //if (decoded==0xD4){ 00051 // DC = DC- 0.01; 00052 // if (DC<0) DC=0; 00053 //} 00054 //if (decoded==0xC3){ 00055 // DC = 0.5; 00056 //} 00057 00058 // my_pwm1.write(DC); 00059 // my_pwm2.write(DC); 00060 00061 00062 /* DEBUG 00063 for (int i = 0; i < bitcount; i++) { 00064 pc.printf("%02X", buf[i]); 00065 } 00066 */ 00067 00068 } else myled=0; 00069 00070 } 00071 }
Generated on Thu Jul 21 2022 09:28:40 by 1.7.2