arduino 格力遥控 红外解码 YB0F2 遥控 DIY

解码过程和发送过程参见帖子一,数据扩展参见帖子二。

帖子一:

https://www.arduino.cn/thread-3618-1-1.html

一、解码程序

// 奈何哥哥教你推倒Arduino-红外遥控~

#include 
 
int RECV_PIN = 11;
 
IRrecv irrecv(RECV_PIN);
 
decode_results results;
 
void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); 
}
 
void dump(decode_results *results) {
  int count = results->rawlen;
  Serial.print("Raw (");
  Serial.print(count, DEC);
  Serial.print("): ");
 
  for (int i = 0; i < count; i++) {
    if ((i % 2) == 1) {
      Serial.print((int)results->rawbuf[i]*USECPERTICK, DEC);
    } //原贴此处有错误
    else {
      Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC);
    }//原贴此处有错误
    Serial.print(" ");
  }
  Serial.println("");
}
 
 
void loop() {
  if (irrecv.decode(&results)) {
    dump(&results);
    irrecv.resume(); 
  }
}

二、发送程序

//奈何哥哥和你一起逆袭Arduino~红外控制
#include 
 
IRsend irsend;
unsigned int buf[243]=
    {8300,4150,550,600,500,1550,600,1600,500,600,500,1600,550,600,500,1550,600,500,550,1650,500,1600,550,1600,550,550,550,1550,550,1650,500,1650,500,550,550,550,550,550,500,550,550,550,550,550,500,600,500,600,500,550,500,1600,550,550,550,550,550,550,500,550,550,550,550,600,450,600,450,600,550,1600,550,550,500,600,500,550,550,1600,550,550,500,550,550,550,550,550,550,550,500,550,550,550,550,550,500,550,550,550,550,550,550,550,500,550,550,550,500,600,500,550,550,550,550,550,500,600,500,550,550,550,500,600,500,550,550,550,500,600,500,550,550,550,550,550,500,550,550,550,550,550,500,550,550,550,550,550,500,600,500,550,550,550,500,600,500,550,550,550,550,550,500,550,550,550,550,550,550,550,500,550,550,550,550,550,500,550,550,550,550,550,500,550,550,550,550,550,500,600,500,550,550,550,500,600,500,550,550,550,550,550,500,550,550,550,550,550,500,600,500,550,550,550,500,600,500,550,550,550,500,600,500,550,550,550,550,550,500,550,550,1600,550,1600,550,1600,550,1600,550,500,550,550,550,550,550
};
//格力空调开机关机时140位。
 
void setup()
{
}
 
void loop() {
  irsend.sendRaw(buf,243,38);
  delay(3000);
}

重要

1:上述方法无法解码程序有问题,无法解码长度超过255,采用下面帖子修改源文件可以解决。

2: 采用IRremote最新的2.2.3版本。

================================================================================================================================================================================================================================================

帖子二:

https://www.geek-workshop.com/thread-5146-1-1.html

IRremote源代码的修改

1三个文件

你要找到如下三个文件
IRremote.ccp IRremote.h IRremoteInt.h ,在 arduino 安装目录下的libraries\arduino_iremote_master
也就是你的库文件,如果没有请参考帖子下载

2 修改IRremote.h

#define RAWBUF 270 // Length of raw duration buffer

// Marks tend to be 100us too long, and spaces 100us too short
// when received due to sensor lag.

这个默认值是100,因为我们接收的数据会超过100,所以在这里改成270,当然你也可以根据需要继续扩大

3 修改IRremoteInt.h

3.1 改 _GAP

#define _GAP 50000 // Minimum map between transmissions

默认的数据是5000,因为遥控器会连续发两段代码,所以5000这个参数不适用,需要改到50000,否则你只能
接受到前一段代码仍然无法控制你家的空调

3.2 改 rawlen

// information for the interrupt handler
typedef struct {
  uint8_t recvpin;           // pin for IR data from detector
  uint8_t rcvstate;          // state machine
  uint8_t blinkflag;         // TRUE to enable blinking of pin 13 on IR processing
  unsigned int timer;     // state timer, counts 50uS ticks.
  unsigned int rawbuf[RAWBUF]; // raw data
// uint8_t rawlen;         // counter of entries in rawbuf
int rawlen;
}
irparams_t;

这段代码我们要修改的 rawlen的定义,在默认库中这个数据被定义为uint8 也就是 一个字节的整数,最大只能到255
所以我们将此参数改成int

***注意:***最新版的IRremote中,上述参数都在IRremoteInt.h中。建议用VScode修改文件。

==================================================================================================================================================================================================================================================

成功例子:格力空调YB0F2遥控红外码如下:

其中

  • 设置 RAWBUF 500

  • 设置 _GAP 50000

开机(140位):

8900,4400,650,550,650,550,600,600,600,1650,650,550,650,550,600,600,600,600,550,1700,600,600,600,600,600,1650,600,600,600,600,550,600,600,600,600,600,600,600,600,550,600,600,600,600,600,1650,650,550,650,500,650,550,650,550,650,550,600,600,600,1700,550,600,600,1650,650,600,550,600,600,1700,600,600,550,19750,700,550,600,600,600,600,600,550,650,550,600,550,650,550,650,550,600,600,600,600,600,600,600,600,550,600,650,1600,700,550,550,600,600,600,600,550,650,550,650,550,650,550,650,550,600,600,600,600,600,550,650,550,600,550,650,550,600,1700,600,550,650,1650,650,1600,650,14982

关机(140位):

8900,4400,650,600,600,550,650,550,600,600,600,600,600,600,600,600,550,600,600,1650,650,600,600,550,600,1700,600,550,600,600,600,600,600,600,600,600,600,550,600,600,600,600,600,600,600,1650,600,600,600,550,650,600,550,600,600,600,600,600,600,1650,600,600,600,1700,550,600,600,600,600,1700,550,600,600,19750,650,600,600,600,550,650,550,600,600,600,600,550,650,550,600,600,600,600,600,600,600,600,600,550,600,600,600,1650,650,550,600,600,600,600,600,600,600,600,550,600,600,600,600,550,650,600,550,600,600,600,600,550,650,600,600,600,550,1650,650,550,650,1650,600,600,600,27234

你可能感兴趣的:(arduino,红外遥控解码)