2017-06-13 49 views
1

我想克隆使用Arduino的AC遠程。我讀使用此代碼的IR信號:使用Arreino與IRremote庫克隆遠程

#include <IRremote.h> 

int RECV_PIN = 11;  
IRrecv irrecv(RECV_PIN); 
decode_results results; 

void setup() { 
    Serial.begin(9600); 
    irrecv.enableIRIn(); // Start the receiver 
} 

// Dumps out the decode_results structure. 
// Call this after IRrecv::decode() 
// void * to work around compiler issue 
//void dump(void *v) { 
// decode_results *results = (decode_results *)v 
void dump(decode_results *results) { 
    int count = results->rawlen; 
    if (results->decode_type == UNKNOWN) { 
    Serial.print("Unknown encoding: "); 
    } else if (results->decode_type == NEC) { 
    Serial.print("Decoded NEC: "); 
    } else if (results->decode_type == SONY) { 
    Serial.print("Decoded SONY: "); 
    } else if (results->decode_type == RC5) { 
    Serial.print("Decoded RC5: "); 
    } else if (results->decode_type == RC6) { 
    Serial.print("Decoded RC6: "); 
    } else if (results->decode_type == PANASONIC) { 
    Serial.print("Decoded PANASONIC - Address: "); 
    Serial.print(results->panasonicAddress,HEX); 
    Serial.print(" Value: "); 
    } else if (results->decode_type == JVC) { 
    Serial.print("Decoded JVC: "); 
    } 
    Serial.print(results->value, HEX); 
    Serial.print(" ("); 
    Serial.print(results->bits, DEC); 
    Serial.println(" bits)"); 
    Serial.print("Raw ("); 
    Serial.print(count, DEC); 
    Serial.print("): "); 
    for (int i = 0; i < count; i++) { 
    if ((i % 2) == 1) { 
     Serial.print(results->rawbuf[i]*USECPERTICK, DEC); 
    } else { 
     Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC); 
    } 
    Serial.print(" "); 
    } 
    Serial.println(""); 
} 

void loop() { 
    if (irrecv.decode(&results)) { 
    Serial.println(results.value, HEX); 
    dump(&results); 
    irrecv.resume(); // Receive the next value 
    } 
} 

然後,我用這個代碼把它發送給AC:

#include <IRremote.h> 

IRsend irsend; 

void setup() { 
} 

void loop() { 
    for (int i = 0; i < 3; i++) { 
    irsend.sendNEC(0xC64E80C, 32); 
    delay(40); 
    } 
    delay(5000); //5 second delay between each signal burst 
} 

我用2個獨立的Arduinos用於測試目的。但不管怎樣,即使hexa值相同,內容也不會以相同的方式發送。

使用遙控器發送的IR信號有108個值,來自Arduino的IR信號只有68個值。

ARDUINO OUTPUT

我試圖改變遠程紅外與我的Arduino IR LED指示燈,它工作得很好。這不是硬件問題。

任何想法?

回答

0

嗨,我也做了同樣的事情。我正在使用它來獲取GREE AC的AC代碼。我經歷了兩週的奮鬥和一個名爲AnalysIR的論壇。如果您在下面的代碼中發現任何問題或方法讓我知道。

AC代碼通常很長,那些代碼並不正確,所以我給你提供代碼在Arduino草圖中運行,以便測試。

#define LEDPIN 13 
    //you may increase this value on Arduinos with greater than 2k SRAM 
    #define maxLen 800 

     volatile unsigned int irBuffer[maxLen]; 
     //stores timings - volatile because changed by ISR 
     volatile unsigned int x = 0; 
     //Pointer thru irBuffer - volatile because changed by ISR 

    void setup() { 
    Serial.begin(115200); //change BAUD rate as required 
    attachInterrupt(0, rxIR_Interrupt_Handler, CHANGE); 
    //set up ISR for receiving IR signal 
    } 

void loop() { 
    // put your main code here, to run repeatedly: 

    Serial.println(F("Press the button on the remote now - once only")); 
    delay(5000); // pause 5 secs 
    if (x) { //if a signal is captured 
digitalWrite(LEDPIN, HIGH);//visual indicator that signal received 
Serial.println(); 
Serial.print(F("Raw: (")); //dump raw header format - for library 
Serial.print((x - 1)); 
Serial.print(F(") ")); 
detachInterrupt(0);//stop interrupts & capture until finshed here 

for (int i = 1; i < x; i++) { //now dump the times 
    if (!(i & 0x1)) Serial.print(F("-")); 
    Serial.print(irBuffer[i] - irBuffer[i - 1]); 
    Serial.print(F(", ")); 
        } 

    x = 0; 
    Serial.println(); 
    Serial.println(); 
    digitalWrite(LEDPIN, LOW);//end of visual indicator, for this time 
    attachInterrupt(0, rxIR_Interrupt_Handler, CHANGE);//re-enable ISR for   receiving IR signal 
     } 

     } 

    void rxIR_Interrupt_Handler() { 
    if (x > maxLen) return; //ignore if irBuffer is already full 
    irBuffer[x++] = micros(); //just continually record the time-stamp of signal transitions 

    } 

完成此操作後,您將獲得將其發送到AC的正確代碼。

有點棘手部分

一旦你將收到你將不得不小修改它例如原始值的代碼我得到了原始值,我將它轉換到陣列中。

我收到什麼例如 原料(16):-27750,4464,696,1612,692,516,688,516,688,1620,692,512,692,1612,696,1612, 692,512,692,516,688,1616,696,1612,692,512,696,512,692,512,692,512,696,512,692,512,692,512,696,512,692, 512,692,512,696,1612,692,1612,692,516,688,516,692,516,688,516,688,516,692,1612,692,516,688,1620,688,516, 688,520,684,1620,660,544,664,19960,628,1680,628,1676,628,580,628,1676,628,580,624,580,628,576,628,580,628, 584,620,576,628,580,628,576,628,576,628,580,624,1680,628,580,624,580,628,580,624,580,628,576,628,580, 624,580,628,576,628,580,628,576,628,580,624,580,628,576,628,1680,624,580,628,1676,628,1680,628,

若要將上述原始值轉換爲數組,請刪除第一個值-27750,並將3800替換爲該值。以下是數組示例。**

無符號整型數據[] = {3800,4464,696,1612,692,516,688,516,688,1620,692,512,692,1612,696,1612,692,512,692 ,516,688,1616,696,1612,692,512,696,512,692,512,692,512,696,512,692,512,692,512,696,512,692,512,692,512 ,696,1612,692,1612,692,516,688,516,692,516,688,516,688,516,692,1612,692,516,688,1620,688,516,688,520,684 ,1620,660,544,664,19960,628,1680,628,1676,628,580,628,1676,628,580,624,580,628,576,628,580,628,584,620,576 ,628,580,628,576,628,576,628,580,624,1680,628,580,624,580,628,580,624,580,628,576,628,580,624,580,628,以及其中的任何一個或多個, ,576,628,580,628,576,628,580,624,580,628,576,628,1680,624,580,628,1676,628,1680,628, };

現在將這些值發送到紅外發射器使用下面的代碼。

 #include<IRremote.h> 
     IRsend irsend; 
     int KHz = 38;     // default frequency 

     unsigned int data[] = {3800, 4464, 696, 1612, 692, 516, 688, 516, 688, 1620, 692, 512, 692, 1612, 696, 1612, 692, 512, 692, 516, 688, 1616, 696, 1612, 692, 512, 696, 512, 692, 512, 692, 512, 696, 512, 692, 512, 692, 512, 696, 512, 692, 512, 692, 512, 696, 1612, 692, 1612, 692, 516, 688, 516, 692, 516, 688, 516, 688, 516, 692, 1612, 692, 516, 688, 1620, 688, 516, 688, 520, 684, 1620, 660, 544, 664, 19960, 628, 1680, 628, 1676, 628, 580, 628, 1676, 628, 580, 624, 580, 628, 576, 628, 580, 628, 584, 620, 576, 628, 580, 628, 576, 628, 576, 628, 580, 624, 1680, 628, 580, 624, 580, 628, 580, 624, 580, 628, 576, 628, 580, 624, 580, 628, 576, 628, 580, 628, 576, 628, 580, 624, 580, 628, 576, 628, 1680, 624, 580, 628, 1676, 628, 1680, 628, 
     }; 


    void setup() 
    { 
    Serial.begin(9600); 
    irsend.enableIROut(38); 
    } 

    void loop() 
    { 

    for (int i=0; i<1 ; i++){ 
    irsend.sendRaw(data, sizeof(data)/sizeof(int),38); 
    delay(40); 
      } 


}