iT邦幫忙

0

能請大神簡單幫我講一下這串範例的程式碼在寫什麼嗎

#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) {

        }
    }
}

}

看更多先前的討論...收起先前的討論...
大哉問,這個應該是Arduino的程式碼,猜是接收紅外線感測器訊號,特定訊號就用蜂鳴器發出聲音
沒錯 但我不是很確定每個部份到底做了什麼事情所以需要麻煩各位幫忙翻譯一下
你的程式拜託重貼一下,這樣很難閱讀,把程式碼框在 </> 裡
ㄜ...不好一思剛接觸寫程式,不確定到底您需要什麼
Homura iT邦高手 1 級 ‧ 2021-02-18 16:12:29 檢舉
他是說你文章程式碼太亂了
請用
```

```
包起來
邦幫忙的發文網頁編輯器裡有個</>的鍵,按下去會出現兩排 ``` 把你的原始碼放到那中間就好
0
I code so I am
iT邦研究生 3 級 ‧ 2021-02-19 10:06:47

Anduino 控制紅外線開關吧。

1
Peter學程式
iT邦新手 2 級 ‧ 2021-02-19 10:27:24

在這邊發問之前,小弟建議:

  1. 學習 Markdown ,讓你的程式碼容易閱讀:
#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) {

        }
    }
}
}
  1. 不要將問題全都打在標題上,請參考提問的智慧

再來,因為你沒有明確表達你的問題,我只能猜測你對前置處理器不夠了解:

0
Cheng®
iT邦新手 5 級 ‧ 2021-02-23 18:01:03

應該是這個吧
Arduino-IRremote

我要發表回答

立即登入回答