Skip to content

Commit f570ed2

Browse files
committed
Added MultipleSendPins example
1 parent 87201d6 commit f570ed2

File tree

8 files changed

+110
-5
lines changed

8 files changed

+110
-5
lines changed

.github/workflows/LibraryBuild.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ jobs:
100100
All: -DUSE_NO_SEND_PWM
101101

102102
- arduino-boards-fqbn: arduino:avr:uno|SEND_PWM_BY_TIMER
103-
sketches-exclude: UnitTest
103+
sketches-exclude: UnitTest,MultipleSendPins
104104
build-properties: # the flags were put in compiler.cpp.extra_flags
105105
IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=750 -DIR_SEND_PIN=3 -DSEND_PWM_BY_TIMER
106106
ReceiveDemo: -DDECODE_ONKYO

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,9 +562,10 @@ Most of the times, *device* and *subdevice* can be taken as upper and lower byte
562562
An **exact mapping** can be found in the [IRP definition files for IR protocols](https://github.com/probonopd/MakeHex/tree/master/protocols). "D" and "S" denotes device and subdevice and "F" denotes the function.
563563
564564
## Send pin
565-
Any pin can be chosen as send pin, because the PWM signal is generated by default with software bit banging, since `SEND_PWM_BY_TIMER` is not active.<br/>
565+
Any pin can be chosen as send pin as long as `IR_SEND_PIN` is **not** defined.
566+
This is because the PWM signal is generated by default with software bit banging, since `SEND_PWM_BY_TIMER` is not active.<br/>
566567
On **ESP32** ledc channel 0 is used for generating the IR PWM.<br/>
567-
If `IR_SEND_PIN` is specified (as c macro), it reduces program size and improves send timing for AVR. If you want to use a variable to specify send pin e.g. with `setSendPin(uint8_t aSendPinNumber)`, you must disable this `IR_SEND_PIN` macro.
568+
If `IR_SEND_PIN` is specified (as C macro), it reduces program size and improves send timing for AVR. If you want to use a variable to specify send pin e.g. with `setSendPin(uint8_t aSendPinNumber)`, you must disable this `IR_SEND_PIN` macro e.g. with `#undef IR_SEND_PIN`.
568569
Then you can change send pin at any time before sending an IR frame. See also [Compile options / macros for this library](https://github.com/Arduino-IRremote/Arduino-IRremote?tab=readme-ov-file#compile-options--macros-for-this-library).
569570
570571
### List of public IR code databases
@@ -767,6 +768,9 @@ Receives all protocols and dumps the received signal in different flavors includ
767768
#### SendDemo
768769
Sends all available protocols at least once.
769770

771+
#### MultipleSendPins
772+
Demonstrates sending IR codes toggling between 2 **different send pins**.
773+
770774
#### SendAndReceive
771775
Demonstrates **receiving while sending**.
772776

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ See also the commit log at github: https://github.com/Arduino-IRremote/Arduino-I
77
- attachInterrupt() on SAMD has a different semantic :-(. See: https://www.arduino.cc/reference/tr/language/functions/external-interrupts/attachinterrupt/.
88
- Fixed overflow handling.
99
- Improved repeat detection for DistanceWidthProtocol.
10+
- Print of IR frame duration in printIRResultShort();
1011

1112
# 4.4.1
1213
- Support for ESP core 3.x by akellai.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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+
}

examples/SimpleSender/SimpleSender.ino

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
*
44
* Demonstrates sending IR codes in standard format with address and command
55
* An extended example for sending can be found as SendDemo.
6+
* Sending IR codes using several pins for sending is implements in the MultipleSendPins example.
67
*
7-
* Copyright (C) 2020-2022 Armin Joachimsmeyer
8+
* Copyright (C) 2020-2025 Armin Joachimsmeyer
89
910
*
1011
* This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.

src/IRProtocol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ const __FlashStringHelper* getProtocolString(decode_type_t aProtocol);
171171
#else
172172
const char* getProtocolString(decode_type_t aProtocol);
173173
#endif
174+
void printIRResultShort(Print *aSerial, IRData *aIRDataPtr, bool aPrintRepeatGap) __attribute__ ((deprecated ("Remove last parameter, it is not supported any more.")));
174175
void printIRResultShort(Print *aSerial, IRData *aIRDataPtr); // A static function to be able to print send or copied received data.
175176

176177
/*

src/IRProtocol.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ namespace PrintULL {
160160
* @param aPrintRepeatGap If true also print the gap before repeats.
161161
*
162162
*/
163+
void printIRResultShort(Print *aSerial, IRData *aIRDataPtr, bool aPrintRepeatGap) {
164+
(void) aPrintRepeatGap;
165+
printIRResultShort(aSerial, aIRDataPtr);
166+
}
163167
void printIRResultShort(Print *aSerial, IRData *aIRDataPtr) {
164168
if (aIRDataPtr->flags & IRDATA_FLAGS_WAS_OVERFLOW) {
165169
aSerial->println(F("Overflow"));

src/IRremoteInt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ class IRsend {
470470
// The next function is a dummy to avoid acceptance of pre 4.3 calls to begin(DISABLE_LED_FEEDBACK);
471471
void begin(uint8_t aSendPin)
472472
# if !defined (DOXYGEN)
473-
__attribute__ ((deprecated ("Error: IR_SEND_PIN is still defined, therefore the function begin(aSendPin) is NOT available. You must disable '#define IR_SEND_PIN' to enable this function.")));
473+
__attribute__ ((deprecated ("ERROR: IR_SEND_PIN is still defined, therefore the function begin(aSendPin) is NOT available. You must disable '#define IR_SEND_PIN' to enable this function.")));
474474
# endif
475475

476476
// The next function is a dummy to avoid acceptance of pre 4.0 calls to begin(IR_SEND_PIN, DISABLE_LED_FEEDBACK);

0 commit comments

Comments
 (0)