调通了自家格力空调的红外遥控(Y502E型号的遥控器),这里记录和分享下:
直接通过IRremote dmp出遥控器的开关代码,注意这里修改了下IRremote的例子,同时把输出的第一位移到最后去。
如:关闭的编码中,15248 dmp出来时在最前面,移动到最后即可。
其它没有什么好说明的了,直接上代码:
- #include <IRremote.h>
- unsigned int rawCodes_ac_close[74] ={8900,4450,650,1650,600,550,650,550,600,600,600,550,650,550,600,550,650,550,600,550,650,1650,650,550,650,1600,650,550,650,550,650,500,650,550,650,500,650,550,650,500,650,550,650,550,650,500,650,550,650,500,650,550,650,550,650,500,650,550,650,1600,650,550,650,1650,600,550,650,550,650,1600,650,550,650,15248};
- unsigned int rawCodes_ac_open[74] ={8950,4400,650,1650,650,500,650,550,650,1650,650,550,650,500,650,550,600,600,600,550,650,1650,650,500,650,1650,650,550,650,500,650,550,650,500,650,550,650,550,650,500,650,550,650,500,650,550,650,550,650,500,650,550,650,500,650,550,650,500,650,1650,650,550,650,1600,650,550,650,550,600,1650,650,550,650,32896};
- IRsend irsend;
- int RECV_PIN = 11;
- IRrecv irrecv(RECV_PIN);
- decode_results results;
- void setup()
- {
- Serial.begin(9600);
- irrecv.enableIRIn(); // Start the receiver
- }
- void loop(){
- irsend.sendRaw(rawCodes_ac_close,74, 38);
- // if (irrecv.decode(&results)) {
- // Serial.println(results.value, HEX);
- // dump(&results);
- // irrecv.resume(); // Receive the next value
- // }
- delay(5000);
- irsend.sendRaw(rawCodes_ac_open,74, 38);
- delay(5000);
- }
- 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++) {
- Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
- Serial.print(",");
- }
- Serial.println("");
- }
复制代码 |