# 7. 红外遥控

BiBoard配置了红外传感器，连接在第23引脚。红外的使用和基于AVR的UNO完全一样。

首先下载2.6.1版本的IRremote库，需要手工选择2.6.1版本。因为之后的版本红外编码有变化，如果使用3.X版本，指令会无法被翻译。为了同我们之前的产品兼容，测试后决定使用2.6.1版本。

![](/files/-MX3dEbaFtWAxhy0O4mc)

在使用NyBoard的时候，为了保证代码可以顺利编译，我们需要给IRremote库进行“瘦身”，即去掉我们用不到的编码/解码器，只保留NEC\_DECODER即NEC格式的38KHz信号解码器。

在Flash巨大的BiBoard上，我们无需进行“瘦身”。

![UNO使用了23%的Flash](/files/-MX3eeH11NmVROtpAZva)

![BiBoard只使用的4%](/files/-MX3eOhuD7etiCi0wsCt)

最后附上例程，接受红外信号并串口打印，也可以使用官方的例程进行测试。

```
#include <Arduino.h>
#include <IRremote.h>

int RECV_PIN = 23;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup() {
  Serial.begin(115200);
  irrecv.enableIRIn();
  Serial.println("IR Receiver ready");
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    Serial.print(" - ");
    irrecv.resume(); // Receive the next value
  }
  delay(300);
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.petoi.com/chinese/biboard/li-cheng/7.-hong-wai-yao-kong.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
