我有一个红外LED,使用以下代码发送红外信号:
#include <IRremote.h>
IRsend irsend;
const int buttonPin = 8; // the number of the pushbutton pin
//const int ledPin = 3;
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
Serial.begin(9600);
}
void loop() {
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(7, HIGH);
irsend.sendNEC(0x1FE08F7, 32);
} else {
digitalWrite(7,LOW);
}
}
当我使用以下代码在另一个Arduino上使用IR接收器打印信号时:
#include <IRremote.h>
const int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup() {
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
irrecv.blink13(true);
}
void loop() {
if (irrecv.decode(&results)) {
if (results.decode_type == NEC) {
Serial.print("NEC: ");
} else if (results.decode_type == SONY) {
Serial.print("SONY: ");
} else if (results.decode_type == RC5) {
Serial.print("RC5: ");
} else if (results.decode_type == RC6) {
Serial.print("RC6: ");
} else if (results.decode_type == UNKNOWN) {
Serial.print("UNKNOWN: ");
}
Serial.println(results.value, HEX);
Serial.println(results.value);
irrecv.resume(); // Receive the next value
}
}
串行监视器输出是:
UNKNOWN: BDD27AF2
3184687858
UNKNOWN: BDD27AF2
3184687858
UNKNOWN: BDD27AF2
3184687858
1FE
510
1FE
510
NEC: 1FE08F7
33425655
1FE
510
UNKNOWN: BDD27AF2
3184687858
1FE
510
UNKNOWN: BDD27AF2
3184687858
1FE
510
UNKNOWN: BDD27AF2
3184687858
1FE
510
UNKNOWN: BDD27AF2
3184687858
UNKNOWN: BDD27AF2
3184687858
UNKNOWN: BDD27AF2
3184687858
UNKNOWN: BDD27AF2
3184687858
1FE
510
UNKNOWN: BDD27AF2
3184687858
NEC: 1FE08F7
33425655
UNKNOWN: BDD27AF2
3184687858
输出不一致。我的发言人我写的HEX代码也没有响应任何信号。我正在寻找这个问题几个小时但找不到任何解决方案。
任何帮助将不胜感激。提前谢谢!