|
| 1 | +/* |
| 2 | + * MultipleSendPins.cpp |
| 3 | + * |
| 4 | + * Demonstrates sending IR codes toggling between 2 different send pins. |
| 5 | + * Based on SimpleSender. |
| 6 | + * |
| 7 | + * Copyright (C) 2025 Armin Joachimsmeyer |
| 8 | + |
| 9 | + * |
| 10 | + * This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. |
| 11 | + * |
| 12 | + * MIT License |
| 13 | + */ |
| 14 | +#include <Arduino.h> |
| 15 | + |
| 16 | +#if !defined(ARDUINO_ESP32C3_DEV) // This is due to a bug in RISC-V compiler, which requires unused function sections :-(. |
| 17 | +#define DISABLE_CODE_FOR_RECEIVER // Disables static receiver code like receive timer ISR handler and static IRReceiver and irparams data. Saves 450 bytes program memory and 269 bytes RAM if receiving functions are not required. |
| 18 | +#endif |
| 19 | +//#define USE_NO_SEND_PWM // Use no carrier PWM, just simulate an active low receiver signal. Overrides SEND_PWM_BY_TIMER definition |
| 20 | + |
| 21 | +#include <IRremote.hpp> // include the library |
| 22 | + |
| 23 | +void setup() { |
| 24 | + pinMode(LED_BUILTIN, OUTPUT); |
| 25 | + |
| 26 | + Serial.begin(115200); |
| 27 | + |
| 28 | + // Just to know which program is running on my Arduino |
| 29 | + Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE)); |
| 30 | + Serial.print(F("Send IR signals alternating at pin 3 and 4")); |
| 31 | + |
| 32 | + /* |
| 33 | + * The IR library setup. That's all! |
| 34 | + */ |
| 35 | + IrSender.begin(3); // Start with pin3 as send pin and enable feedback LED at default feedback LED pin |
| 36 | + disableLEDFeedback(); // Disable feedback LED at default feedback LED pin |
| 37 | +} |
| 38 | + |
| 39 | +/* |
| 40 | + * Set up the data to be sent. |
| 41 | + * For most protocols, the data is build up with a constant 8 (or 16 byte) address |
| 42 | + * and a variable 8 bit command. |
| 43 | + * There are exceptions like Sony and Denon, which have 5 bit address. |
| 44 | + */ |
| 45 | +uint8_t sCommand = 0x34; |
| 46 | +uint8_t sRepeats = 0; |
| 47 | + |
| 48 | +void loop() { |
| 49 | + /* |
| 50 | + * Print current send values |
| 51 | + */ |
| 52 | + Serial.println(); |
| 53 | + Serial.print(F("Send now: address=0x00, command=0x")); |
| 54 | + Serial.print(sCommand, HEX); |
| 55 | + Serial.print(F(", repeats=")); |
| 56 | + Serial.print(sRepeats); |
| 57 | + Serial.println(); |
| 58 | + |
| 59 | + Serial.println(F("Send standard NEC with 8 bit address")); |
| 60 | + Serial.flush(); |
| 61 | + |
| 62 | + // Receiver output for the first loop must be: Protocol=NEC Address=0x102 Command=0x34 Raw-Data=0xCB340102 (32 bits) |
| 63 | + IrSender.sendNEC(0x00, sCommand, sRepeats); |
| 64 | + |
| 65 | + /* |
| 66 | + * If you want to send a raw HEX value directly like e.g. 0xCB340102 you must use sendNECRaw() |
| 67 | + */ |
| 68 | +// Serial.println(F("Send 32 bit LSB 0xCB340102 with NECRaw()")); |
| 69 | +// IrSender.sendNECRaw(0xCB340102, sRepeats); |
| 70 | + /* |
| 71 | + * If you want to send an "old" MSB HEX value used by IRremote versions before 3.0 like e.g. 0x40802CD3 you must use sendNECMSB() |
| 72 | + */ |
| 73 | +// Serial.println(F("Send old 32 bit MSB 0x40802CD3 with sendNECMSB()")); |
| 74 | +// IrSender.sendNECMSB(0x40802CD3, 32, sRepeats); |
| 75 | + /* |
| 76 | + * Increment send values |
| 77 | + */ |
| 78 | + sCommand += 0x11; |
| 79 | + sRepeats++; |
| 80 | + // clip repeats at 4 |
| 81 | + if (sRepeats > 4) { |
| 82 | + sRepeats = 4; |
| 83 | + } |
| 84 | + |
| 85 | + /* |
| 86 | + * Toggle between send pin 3 and 4 |
| 87 | + */ |
| 88 | + if (IrSender.sendPin == 3) { |
| 89 | + IrSender.setSendPin(4); |
| 90 | + } else { |
| 91 | + IrSender.setSendPin(3); |
| 92 | + } |
| 93 | + delay(1000); // delay must be greater than 5 ms (RECORD_GAP_MICROS), otherwise the receiver sees it as one long signal |
| 94 | +} |
0 commit comments