Skip to content

Commit ed4ee8e

Browse files
committed
renamed IRrecord example to ReceiveAndSend added SimpleReceiver example and changed two functions to static
1 parent 1ea58ba commit ed4ee8e

File tree

16 files changed

+313
-1248
lines changed

16 files changed

+313
-1248
lines changed

.github/workflows/LibraryBuild.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ jobs:
8686

8787
- arduino-boards-fqbn: digistump:avr:digispark-tiny:clock=clock1
8888
platform-url: https://raw.githubusercontent.com/ArminJo/DigistumpArduino/master/package_digistump_index.json
89-
sketches-exclude: IR2Keyboard,IRUnitTest,IRrelay,IRsendDemo,IRrecord,IRreceiveDump,IRsendProntoDemo,MicroGirs,IRreceiveDemo,ReceiverTimingAnalysis,IRDispatcherDemo,LGAirConditionerSendDemo # Does not fit in FLASH or RAM # Comma separated list of example names to exclude in build
89+
sketches-exclude: IR2Keyboard,IRUnitTest,IRrelay,IRsendDemo,ReceiveAndSend,IRreceiveDump,IRsendProntoDemo,MicroGirs,IRreceiveDemo,ReceiverTimingAnalysis,IRDispatcherDemo,LGAirConditionerSendDemo # Does not fit in FLASH or RAM # Comma separated list of example names to exclude in build
9090

9191
- arduino-boards-fqbn: ATTinyCore:avr:attinyx5:chip=85,clock=1internal
9292
platform-url: http://drazzy.com/package_drazzy.com_index.json
93-
sketches-exclude: IR2Keyboard,IRUnitTest,IRrelay,IRrecord,IRreceiveDumpV2,IRsendProntoDemo,MicroGirs,IRreceiveDemo,BoseWaveSendDemo,IRDispatcherDemo,LGAirConditionerSendDemo # Does not fit in FLASH or RAM
93+
sketches-exclude: IR2Keyboard,IRUnitTest,IRrelay,ReceiveAndSend,IRreceiveDumpV2,IRsendProntoDemo,MicroGirs,IRreceiveDemo,BoseWaveSendDemo,IRDispatcherDemo,LGAirConditionerSendDemo # Does not fit in FLASH or RAM
9494

9595
- arduino-boards-fqbn: TinyCore:avr:tiny32
9696
platform-url: https://raw.githubusercontent.com/xukangmin/TinyCore/master/avr/package/package_tinycore_index.json
@@ -107,7 +107,7 @@ jobs:
107107

108108
- arduino-boards-fqbn: sandeepmistry:nRF5:BBCmicrobit
109109
platform-url: https://sandeepmistry.github.io/arduino-nRF5/package_nRF5_boards_index.json
110-
sketches-exclude: BoseWaveSendDemo,IR2Keyboard,IRDispatcherDemo,IRreceiveDemo,IRrecord,IRsendDemo,IRsendProntoDemo,IRsendRawDemo,IRUnitTest,LGAirConditionerSendDemo,MicroGirs,MinimalReceiver,SimpleSender # no sending yet, no tone()
110+
sketches-exclude: BoseWaveSendDemo,IR2Keyboard,IRDispatcherDemo,IRreceiveDemo,ReceiveAndSend,IRsendDemo,IRsendProntoDemo,IRsendRawDemo,IRUnitTest,LGAirConditionerSendDemo,MicroGirs,MinimalReceiver,SimpleSender # no sending yet, no tone()
111111

112112

113113
# Do not cancel all jobs / architectures if one job fails

examples/IRreceiveDemo/IRreceiveDemo.ino

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,14 @@ void loop() {
8787
IrReceiver.resume(); // Enable receiving of the next value
8888

8989
/*
90-
* Finally check the received data and perform actions according to the received commands
90+
* Finally check the received data and perform actions according to the received address and command
9191
*/
92-
if (IrReceiver.decodedIRData.command == 0x10) {
93-
// do something
94-
} else if (IrReceiver.decodedIRData.command == 0x11) {
95-
// do something else
92+
if (IrReceiver.decodedIRData.address == 0) {
93+
if (IrReceiver.decodedIRData.command == 0x10) {
94+
// do something
95+
} else if (IrReceiver.decodedIRData.command == 0x11) {
96+
// do something else
97+
}
9698
}
9799
}
98100
}

examples/IRsendDemo/IRsendDemo.ino

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ void loop() {
7676
"0017 0806"), 0); //stop bit, no repeat possible, because of missing repeat pattern
7777
delay(2000);
7878

79-
Serial.println(F("Send NECRaw 0xCC340102 with 16 bit address 0x102 and command 0x34 which results in a parity error, since CC != ~34"));
79+
Serial.println(
80+
F(
81+
"Send NECRaw 0xCC340102 with 16 bit address 0x102 and command 0x34 which results in a parity error, since CC != ~34"));
8082
IrSender.sendNECRaw(0xCC340102, sRepeats);
8183
delay(2000);
8284
}
@@ -117,16 +119,31 @@ void loop() {
117119
IrSender.sendRC6(sAddress, sCommand, sRepeats, true);
118120
delay(2000);
119121

120-
Serial.println(F("Send Samsung"));
121-
IrSender.sendSamsung(sAddress, sCommand, sRepeats);
122+
/*
123+
* Next example how to use the IrSender.write function
124+
*/
125+
IRData IRSendData;
126+
// prepare data
127+
IRSendData.address = sAddress;
128+
IRSendData.command = sCommand;
129+
IRSendData.flags = IRDATA_FLAGS_EMPTY;
130+
131+
IRSendData.protocol = SAMSUNG;
132+
Serial.print(F("Send "));
133+
Serial.println(getProtocolString(IRSendData.protocol));
134+
IrSender.write(&IRSendData, sRepeats);
122135
delay(2000);
123136

124-
Serial.println(F("Send JVC"));
125-
IrSender.sendJVC(sAddress, sCommand, sRepeats);
137+
IRSendData.protocol = JVC; // switch protocol
138+
Serial.print(F("Send "));
139+
Serial.println(getProtocolString(IRSendData.protocol));
140+
IrSender.write(&IRSendData, sRepeats);
126141
delay(2000);
127142

128-
Serial.println(F("Send LG"));
129-
IrSender.sendLG((uint8_t) sAddress, sCommand, sRepeats);
143+
IRSendData.protocol = LG;
144+
Serial.print(F("Send "));
145+
Serial.println(getProtocolString(IRSendData.protocol));
146+
IrSender.write(&IRSendData, sRepeats);
130147
delay(2000);
131148

132149
if (sRepeats == 0) {
@@ -142,8 +159,9 @@ void loop() {
142159
}
143160

144161
#if !defined(__AVR_ATtiny85__) // code does not fit in program space of ATtiny85
145-
Serial.println(F("Send Bosewave with 8 command bits"));
146-
IrSender.sendBoseWave(sCommand, sRepeats);
162+
IRSendData.protocol = BOSEWAVE;
163+
Serial.println(F("Send Bosewave with no address and 8 command bits"));
164+
IrSender.write(&IRSendData, sRepeats);
147165
delay(2000);
148166

149167
/*

examples/MinimalReceiver/MinimalReceiver.ino

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/*
22
* MinimalReceiver.cpp
33
*
4+
* Small memory footprint and no timer usage!
5+
*
46
* Receives IR protocol data of NEC protocol using pin change interrupts.
57
* On complete received IR command the function handleReceivedIRData(uint16_t aAddress, uint8_t aCommand, bool isRepetition)
68
* is called in Interrupt context but with interrupts being enabled to enable use of delay() etc.
@@ -10,7 +12,7 @@
1012
* !!!!!!!!!!!!!!!!!!!!!
1113
*
1214
*
13-
* Copyright (C) 2021 Armin Joachimsmeyer
15+
* Copyright (C) 2020-2021 Armin Joachimsmeyer
1416
1517
*
1618
* This file is part of IRMP https://github.com/ukw100/IRMP.

examples/IRrecord/IRrecord.ino renamed to examples/ReceiveAndSend/ReceiveAndSend.ino

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* IRrecord.cpp
2+
* ReceiveAndSend.cpp
33
*
44
* Record and play back IR signals as a minimal
55
* An IR detector/demodulator must be connected to the input RECV_PIN.
@@ -14,6 +14,30 @@
1414
* Initially coded 2009 Ken Shirriff http://www.righto.com
1515
*
1616
* This file is part of Arduino-IRremote https://github.com/z3t0/Arduino-IRremote.
17+
*
18+
************************************************************************************
19+
* MIT License
20+
*
21+
* Copyright (c) 2020-2021 Armin Joachimsmeyer
22+
*
23+
* Permission is hereby granted, free of charge, to any person obtaining a copy
24+
* of this software and associated documentation files (the "Software"), to deal
25+
* in the Software without restriction, including without limitation the rights
26+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27+
* copies of the Software, and to permit persons to whom the Software is furnished
28+
* to do so, subject to the following conditions:
29+
*
30+
* The above copyright notice and this permission notice shall be included in all
31+
* copies or substantial portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
34+
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
35+
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
36+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
37+
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
38+
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39+
*
40+
************************************************************************************
1741
*/
1842

1943
#include <IRremote.h>
@@ -37,6 +61,7 @@ int DELAY_BETWEEN_REPEAT = 50;
3761
// Storage for the recorded code
3862
struct storedIRDataStruct {
3963
IRData receivedIRData;
64+
// extensions for sendRaw
4065
uint8_t rawCode[RAW_BUFFER_LENGTH]; // The durations if raw
4166
uint8_t rawCodeLength; // The length of the code
4267
} sStoredIRData;
@@ -160,10 +185,13 @@ void sendCode(storedIRDataStruct *aIRDataToSend) {
160185
Serial.println(F(" marks or spaces"));
161186
} else {
162187

188+
/*
189+
* Use the write function, which does the switch for different protocols
190+
*/
163191
IrSender.write(&aIRDataToSend->receivedIRData, NO_REPEATS);
164192

165193
Serial.print(F("Sent: "));
166-
IrReceiver.printIRResultShort(&Serial, &aIRDataToSend->receivedIRData);
194+
printIRResultShort(&Serial, &aIRDataToSend->receivedIRData);
167195
}
168196
}
169197

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* SimpleReceiver.cpp
3+
*
4+
* Demonstrates receiving NEC IR codes with IRrecv
5+
*
6+
* Copyright (C) 2020-2021 Armin Joachimsmeyer
7+
8+
*
9+
* This file is part of Arduino-IRremote https://github.com/z3t0/Arduino-IRremote.
10+
*
11+
* MIT License
12+
*/
13+
14+
#include <IRremote.h>
15+
16+
int IR_RECEIVE_PIN = 11;
17+
18+
void setup() {
19+
Serial.begin(115200);
20+
// Just to know which program is running on my Arduino
21+
Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));
22+
23+
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); // Start the receiver, enable feedback LED, take LED feedback pin from the internal boards definition
24+
25+
Serial.print(F("Ready to receive IR signals at pin "));
26+
Serial.println(IR_RECEIVE_PIN);
27+
}
28+
29+
void loop() {
30+
/*
31+
* Check if received data is available and if yes, try to decode it.
32+
* Decoded result is in the IrReceiver.decodedIRData structure.
33+
*/
34+
if (IrReceiver.decode()) {
35+
36+
// Print a short summary of received data
37+
IrReceiver.printIRResultShort(&Serial);
38+
if (IrReceiver.decodedIRData.protocol == UNKNOWN) {
39+
// We have an unknown protocol, print more info
40+
IrReceiver.printIRResultRawFormatted(&Serial, true);
41+
}
42+
Serial.println();
43+
IrReceiver.resume(); // Enable receiving of the next value
44+
45+
/*
46+
* Finally check the received data and perform actions according to the received commands
47+
*/
48+
if (IrReceiver.decodedIRData.command == 0x10) {
49+
// do something
50+
} else if (IrReceiver.decodedIRData.command == 0x11) {
51+
// do something else
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)