Skip to content

Commit 2f58516

Browse files
committed
1 parent a267d83 commit 2f58516

File tree

5 files changed

+112
-0
lines changed

5 files changed

+112
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#define DECODE_NEC
2+
#include <IRremote.hpp>
3+
4+
#define IR_RECEIVE_PIN 11
5+
6+
#if !defined(STR_HELPER)
7+
#define STR_HELPER(x) #x
8+
#define STR(x) STR_HELPER(x)
9+
#endif
10+
//const int remotePin = 11;
11+
12+
void setup() {
13+
Serial.begin(9600);
14+
while (!Serial)
15+
; // Wait for Serial to become available. Is optimized away for some cores.
16+
// Just to know which program is running on my Arduino
17+
Serial.println();
18+
Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version: " VERSION_IRREMOTE));
19+
// Start the receiver and if not 3. parameter specified, take LED_BUILTIN pin from the internal boards definition as default feed
20+
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
21+
Serial.print(F("Ready to receive IR signals of protocols: "));
22+
printActiveIRProtocols(&Serial);
23+
Serial.println(F("at pin: " STR(IR_RECEIVE_PIN)));
24+
Serial.println();
25+
}
26+
27+
void loop() {
28+
/*
29+
* Check if received data is available and if yes, try to decode it.
30+
* Decoded result is in the IrReceiver.decodedIRData structure.
31+
*
32+
* E.g. command is in IrReceiver.decodedIRData.command
33+
* address is in command is in IrReceiver.decodedIRData.address
34+
* and up to 32 bit raw data in IrReceiver.decodedIRData.decodedRawData
35+
*/
36+
if (IrReceiver.decode()) {
37+
// Print a summary of received data
38+
if (IrReceiver.decodedIRData.protocol == UNKNOWN) {
39+
Serial.println(F("Received noise or an unknown (or not yet enabled) protocol"));
40+
// We have an unknown protocol here, print extended info
41+
IrReceiver.printIRResultRawFormatted(&Serial, true);
42+
IrReceiver.resume(); // Do it here, to preserve raw data for printing with printIRResultRawFormatted()
43+
} else {
44+
IrReceiver.resume(); // Early enable receiving of the next IR frame
45+
IrReceiver.printIRResultShort(&Serial);
46+
//IrReceiver.printIRSendUsage(&Serial);
47+
}
48+
Serial.println();
49+
50+
// Finally, check the received data and perform actions according to the received command
51+
switch (IrReceiver.decodedIRData.command) {
52+
case 0x40: Serial.print("'OK'"); break;
53+
54+
case 0x46: Serial.print("'Up'"); break;
55+
case 0x15: Serial.print("'Down'"); break;
56+
57+
case 0x52: Serial.print("'0'"); break;
58+
case 0x16: Serial.print("'1'"); break;
59+
case 0x19: Serial.print("'2'"); break;
60+
61+
case 0x42: Serial.print("'*'"); break;
62+
default: Serial.print("'?'");
63+
}
64+
Serial.print("\n\n");
65+
}
66+
}

14-remote_control_ir/readme.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Serial Monitor output:
2+
```
3+
START C:\dan\dev\@Arduino\Study\14-remote_control_ir\14-remote_control_ir.ino from Aug 6 2024
4+
Using library version: 4.4.0
5+
Ready to receive IR signals of protocols: NEC/NEC2/Onkyo/Apple, at pin: 11
6+
7+
Protocol=NEC Address=0x0 Command=0x40 Raw-Data=0xBF40FF00 32 bits LSB first
8+
'OK'
9+
Protocol=NEC Address=0x0 Command=0x46 Raw-Data=0xB946FF00 32 bits LSB first
10+
'Up'
11+
Protocol=NEC Address=0x0 Command=0x16 Raw-Data=0xE916FF00 32 bits LSB first
12+
'1'
13+
Protocol=NEC Address=0x0 Command=0x16 Repeat gap=39450us
14+
'1'
15+
Protocol=NEC Address=0x0 Command=0x52 Raw-Data=0xAD52FF00 32 bits LSB first
16+
'0'
17+
Protocol=NEC Address=0x0 Command=0x42 Raw-Data=0xBD42FF00 32 bits LSB first
18+
'*'
19+
Protocol=NEC Address=0x0 Command=0x4A Raw-Data=0xB54AFF00 32 bits LSB first
20+
'?'
21+
Protocol=NEC Address=0x0 Command=0x4A Repeat gap=39450us
22+
'?'
23+
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const int dataPin = 2; // #14 DS Serial data input
2+
const int clockPin = 5; // #11 SH_CP Shift Register Clock Uoutput
3+
const int latchPin = 4; // #12 ST_CP Storage Register Clock Input
4+
5+
void setup() {
6+
pinMode(dataPin, OUTPUT);
7+
pinMode(clockPin, OUTPUT);
8+
pinMode(latchPin, OUTPUT);
9+
}
10+
11+
void loop() {
12+
for (int i = 0; i < 16; i++) { // 3-LED bit counter
13+
updateLEDs(i << 1); // bitshift 1 coz chip `Q0` output #15 is skipped
14+
delay(1000);
15+
}
16+
}
17+
18+
void updateLEDs(const int byte) {
19+
digitalWrite(latchPin, LOW);
20+
shiftOut(dataPin, clockPin, MSBFIRST, byte); // serial data “output”, high level first
21+
digitalWrite(latchPin, HIGH);
22+
}

16-chip_74HC595/chip_74HC595.webp

7.22 MB
Loading

16-chip_74HC595/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
![](chip_74HC595.webp)

0 commit comments

Comments
 (0)