Arduino IRemote 收发

接收

#include

int PIN_RECV = 11;          // 红外数据接口。
IRrecv irrecv(PIN_RECV);
decode_results results;     // 储存解码结果
int IRVCC = 9;
int IRGND = 10;

void setup()
{
    Serial.begin(9600);
    irrecv.enableIRIn();            // 初始化红外解码
    pinMode(IRVCC, OUTPUT);
    pinMode(IRGND, OUTPUT);

    pinMode(LED_BUILTIN, OUTPUT);

    digitalWrite(IRVCC, HIGH);
    digitalWrite(IRGND, LOW);
}

void loop()
{
    decode_results results;

    // decode returns 1 if something was received
    // otherwise it returns 0
    // The code and protocol type get stored in results
    if (irrecv.decode(&results))
    {
        // The ON/OFF button was pressed on my remote
        // Note: The codes might vary across different remote controls!
        if (results.value == 0xFF609F)
            digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));

        Serial.print(results.bits);
        Serial.print(": ");
        Serial.println(results.value, HEX);

        irrecv.resume(); // Receive the next value
    }
}

发送

#include

IRsend sender;

void setup() {
    sender.begin(PD6);
}

void loop() {
    uint32_t data = 0xFF609F;
    uint8_t len = 32;

    sender.sendNEC(data, len);

    delay(1000);
}

你可能感兴趣的:(Arduino IRemote 收发)