Arduino IRemote 收发
2022-08-01 本文已影响0人
Charles2018
接收
#include<IRremote.h>
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<IRremote.h>
IRsend sender;
void setup() {
sender.begin(PD6);
}
void loop() {
uint32_t data = 0xFF609F;
uint8_t len = 32;
sender.sendNEC(data, len);
delay(1000);
}