|
3 | 3 | * |
4 | 4 | * This example shows how to send a RAW signal using the IRremote library. |
5 | 5 | * The example signal is actually a 32 bit NEC signal. |
6 | | - * Remote Control button: LGTV Power On/Off. |
7 | | - * Hex Value: 0x20DF10EF, 32 bits |
| 6 | + * Protocol=NEC Address=0x4 Command=0x18 Raw-Data=0xE718FB04 32 bits LSB first |
8 | 7 | * |
9 | 8 | * If it is a supported protocol, it is more efficient to use the protocol send function |
10 | 9 | * (here sendNEC) to send the signal. |
|
14 | 13 | ************************************************************************************ |
15 | 14 | * MIT License |
16 | 15 | * |
17 | | - * Copyright (c) 2020-2022 Armin Joachimsmeyer |
| 16 | + * Copyright (c) 2020-2024 Armin Joachimsmeyer |
18 | 17 | * |
19 | 18 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
20 | 19 | * of this software and associated documentation files (the "Software"), to deal |
@@ -68,59 +67,62 @@ void setup() { |
68 | 67 | } |
69 | 68 |
|
70 | 69 | /* |
71 | | - * NEC address=0xFB0C, command=0x18 |
| 70 | + * NEC address=0x04 (0xFB04), command=0x18 (0xE718) |
72 | 71 | * |
73 | | - * This is data in byte format. |
| 72 | + * This is the raw data array in byte format. |
74 | 73 | * The uint8_t/byte elements contain the number of ticks in 50 us. |
75 | 74 | * The uint16_t format contains the (number of ticks * 50) if generated by IRremote, |
76 | 75 | * so the uint16_t format has exact the same resolution but requires double space. |
77 | 76 | * With the uint16_t format, you are able to modify the timings to meet the standards, |
78 | 77 | * e.g. use 560 (instead of 11 * 50) for NEC or use 432 for Panasonic. But in this cases, |
79 | 78 | * you better use the timing generation functions e.g. sendNEC() directly. |
80 | 79 | */ |
81 | | -const uint8_t rawDataP[] |
82 | | -#if defined(__AVR__) |
83 | | -PROGMEM |
84 | | -#endif |
85 | | -= { 180, 90 /*Start bit*/, 11, 11, 11, 11, 11, 34, 11, 34/*0011 0xC of 16 bit address LSB first*/, 11, 11, 11, 11, 11, 11, 11, |
| 80 | +const uint8_t rawDataP[] PROGMEM |
| 81 | += { 180, 90 /*Start bit*/, 11, 11, 11, 11, 11, 34, 11, 11/*0010 0x4 of 8 bit address LSB first*/, 11, 11, 11, 11, 11, 11, 11, |
86 | 82 | 11/*0000*/, 11, 34, 11, 34, 11, 11, 11, 34/*1101 0xB*/, 11, 34, 11, 34, 11, 34, 11, 34/*1111*/, 11, 11, 11, 11, 11, 11, 11, |
87 | 83 | 34/*0001 0x08 of command LSB first*/, 11, 34, 11, 11, 11, 11, 11, 11/*1000 0x01*/, 11, 34, 11, 34, 11, 34, 11, |
88 | 84 | 11/*1110 Inverted 8 of command*/, 11, 11, 11, 34, 11, 34, 11, 34/*0111 inverted 1 of command*/, 11 /*stop bit*/}; |
89 | 85 |
|
| 86 | +/* |
| 87 | + * The same frame as above. Values are NOT multiple of 50, but are taken from the NEC timing definitions |
| 88 | + */ |
| 89 | +const uint16_t rawData[] = { 9000, 4500/*Start bit*/, 560, 560, 560, 560, 560, 1690, 560, |
| 90 | + 560/*0010 0x4 of 8 bit address LSB first*/, 560, 560, 560, 560, 560, 560, 560, 560/*0000*/, 560, 1690, 560, 1690, 560, 560, |
| 91 | + 560, 1690/*1101 0xB - inverted 0x04*/, 560, 1690, 560, 1690, 560, 1690, 560, 1690/*1111 - inverted 0*/, 560, 560, 560, 560, |
| 92 | + 560, 560, 560, 1690/*0001 0x08 of command LSB first*/, 560, 1690, 560, 560, 560, 560, 560, 560/*1000 0x01*/, 560, 1690, 560, |
| 93 | + 1690, 560, 1690, 560, 560/*1110 Inverted 8 of command*/, 560, 560, 560, 1690, 560, 1690, 560, |
| 94 | + 1690/*1111 inverted 0 of command*/, 560 /*stop bit*/}; // Using exact NEC timing |
| 95 | + |
90 | 96 | void loop() { |
91 | 97 |
|
92 | | -#if !(defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)) |
| 98 | +#if FLASHEND > 0x1FFF // For more than 8k flash => not for ATtiny85 etc. |
93 | 99 | /* |
94 | 100 | * Send hand crafted data from RAM |
95 | | - * The values are NOT multiple of 50, but are taken from the NEC timing definitions |
96 | 101 | */ |
97 | | - Serial.println(F("Send NEC 16 bit address=0xFB04 and command 0x08 with exact timing (16 bit array format)")); |
| 102 | + Serial.println(F("Send NEC 8 bit address=0x04 (0xFB04) and command 0x18 (0xE718) with exact timing (16 bit array format)")); |
98 | 103 | Serial.flush(); |
99 | | - |
100 | | - const uint16_t rawData[] = { 9000, 4500/*Start bit*/, 560, 560, 560, 560, 560, 1690, 560, |
101 | | - 560/*0010 0x4 of 16 bit address LSB first*/, 560, 560, 560, 560, 560, 560, 560, 560/*0000*/, 560, 1690, 560, 1690, 560, |
102 | | - 560, 560, 1690/*1101 0xB*/, 560, 1690, 560, 1690, 560, 1690, 560, 1690/*1111*/, 560, 560, 560, 560, 560, 560, 560, |
103 | | - 1690/*0001 0x08 of command LSB first*/, 560, 560, 560, 560, 560, 560, 560, 560/*0000 0x00*/, 560, 1690, 560, 1690, 560, |
104 | | - 1690, 560, 560/*1110 Inverted 8 of command*/, 560, 1690, 560, 1690, 560, 1690, 560, 1690/*1111 inverted 0 of command*/, |
105 | | - 560 /*stop bit*/}; // Using exact NEC timing |
106 | 104 | IrSender.sendRaw(rawData, sizeof(rawData) / sizeof(rawData[0]), NEC_KHZ); // Note the approach used to automatically calculate the size of the array. |
107 | 105 |
|
108 | | - delay(1000); // delay must be greater than 5 ms (RECORD_GAP_MICROS), otherwise the receiver sees it as one long signal |
| 106 | + delay(1000); // delay must be greater than 8 ms (RECORD_GAP_MICROS), otherwise the receiver sees it as one long signal |
| 107 | + |
109 | 108 | #endif |
110 | 109 |
|
111 | 110 | /* |
112 | 111 | * Send byte data direct from FLASH |
113 | 112 | * Note the approach used to automatically calculate the size of the array. |
114 | 113 | */ |
115 | | - Serial.println(F("Send NEC 16 bit address 0xFB0C and data 0x18 with (50 us) tick resolution timing (8 bit array format) ")); |
| 114 | + Serial.println(F("Send NEC 8 bit address 0x04 and command 0x18 with (50 us) tick resolution timing (8 bit array format) ")); |
116 | 115 | Serial.flush(); |
117 | 116 | IrSender.sendRaw_P(rawDataP, sizeof(rawDataP) / sizeof(rawDataP[0]), NEC_KHZ); |
118 | 117 |
|
119 | | - delay(1000); // delay must be greater than 5 ms (RECORD_GAP_MICROS), otherwise the receiver sees it as one long signal |
| 118 | + delay(1000); // delay must be greater than 8 ms (RECORD_GAP_MICROS), otherwise the receiver sees it as one long signal |
120 | 119 |
|
121 | | - Serial.println(F("Send NEC 16 bit address 0x0102, 8 bit data 0x34 with generated timing")); |
| 120 | + /* |
| 121 | + * Send the same frame using NEC encoder |
| 122 | + */ |
| 123 | + Serial.println(F("Send NEC 16 bit address 0x04, 8 bit command 0x18 with NEC encoder")); |
122 | 124 | Serial.flush(); |
123 | | - IrSender.sendNEC(0x0102, 0x34, 0); |
| 125 | + IrSender.sendNEC(0x04, 0x18, 0); |
124 | 126 |
|
125 | 127 | delay(3000); |
126 | 128 | } |
0 commit comments