#define MARK_EXCESS_MICROS 20 // 20 is recommended for the cheap VS1838 modules
#include <IRremote.h>
#if defined(ESP32)
int IR_RECEIVE_PIN = 6;
#elif defined(ARDUINO_AVR_PROMICRO)
#else
#endif
#define BUZZER_PIN 5
#define DEBUG_BUTTON_PIN 6
#if defined(ARDUINO_ARCH_SAMD)
#define Serial SerialUSB
#endif
void setup() {
pinMode(7, OUTPUT);
pinMode(6, INPUT_PULLUP);
Serial.begin(115200);
#if defined(AVR_ATmega32U4) || defined(SERIAL_USB) || defined(SERIAL_PORT_USBVIRTUAL) || defined(ARDUINO_attiny3217)
delay(2000);
#endif
Serial.println("Enabling IRin");
IrReceiver.begin(6, ENABLE_LED_FEEDBACK);
}
void loop() {
if (IrReceiver.decode()) {
if (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_WAS_OVERFLOW) {
IrReceiver.decodedIRData.flags = false;
Serial.println(F("Overflow detected"));
#if !defined(ESP32)
IrReceiver.stop();
tone(BUZZER_PIN, 1100, 10);
delay(50);
#endif
} else {
IrReceiver.printIRResultShort(&Serial);
if (IrReceiver.decodedIRData.protocol == UNKNOWN || digitalRead(DEBUG_BUTTON_PIN) == LOW) {
IrReceiver.printIRResultRawFormatted(&Serial, true);
}
}
#if !defined(ESP32)
IrReceiver.stop();
tone(BUZZER_PIN, 2200, 10);
delay(11);
IrReceiver.start();
#endif
IrReceiver.resume();
if (IrReceiver.decodedIRData.address == 0) {
if (IrReceiver.decodedIRData.command == 0x10) {
} else if (IrReceiver.decodedIRData.command == 0x11) {
}
}
}
}
在這邊發問之前,小弟建議:
#define MARK_EXCESS_MICROS 20 // 20 is recommended for the cheap VS1838 modules
#include <IRremote.h>
#if defined(ESP32)
int IR_RECEIVE_PIN = 6;
#elif defined(ARDUINO_AVR_PROMICRO)
#else
#endif
#define BUZZER_PIN 5
#define DEBUG_BUTTON_PIN 6
#if defined(ARDUINO_ARCH_SAMD)
#define Serial SerialUSB
#endif
void setup() {
pinMode(7, OUTPUT);
pinMode(6, INPUT_PULLUP);
Serial.begin(115200);
#if defined(AVR_ATmega32U4) || defined(SERIAL_USB) || defined(SERIAL_PORT_USBVIRTUAL) || defined(ARDUINO_attiny3217)
delay(2000);
#endif
Serial.println("Enabling IRin");
IrReceiver.begin(6, ENABLE_LED_FEEDBACK);
}
void loop() {
if (IrReceiver.decode()) {
if (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_WAS_OVERFLOW) {
IrReceiver.decodedIRData.flags = false;
Serial.println(F("Overflow detected"));
#if !defined(ESP32)
IrReceiver.stop();
tone(BUZZER_PIN, 1100, 10);
delay(50);
#endif
} else {
IrReceiver.printIRResultShort(&Serial);
if (IrReceiver.decodedIRData.protocol == UNKNOWN || digitalRead(DEBUG_BUTTON_PIN) == LOW) {
IrReceiver.printIRResultRawFormatted(&Serial, true);
}
}
#if !defined(ESP32)
IrReceiver.stop();
tone(BUZZER_PIN, 2200, 10);
delay(11);
IrReceiver.start();
#endif
IrReceiver.resume();
if (IrReceiver.decodedIRData.address == 0) {
if (IrReceiver.decodedIRData.command == 0x10) {
} else if (IrReceiver.decodedIRData.command == 0x11) {
}
}
}
}
再來,因為你沒有明確表達你的問題,我只能猜測你對前置處理器
不夠了解: