1
1
/*
2
- * AllProtocols .cpp
2
+ * AllProtocolsOnLCD .cpp
3
3
*
4
- * Modified ReceiveDemo.cpp with additional LCD output.
4
+ * Modified ReceiveDemo.cpp with additional 1602 LCD output.
5
5
* If debug button is pressed (pin connected to ground) a long output is generated.
6
6
*
7
7
* This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
73
73
* because of the long lasting serial communication.
74
74
*/
75
75
// #define USE_NO_LCD
76
- #define USE_SERIAL_LCD
76
+ // #define USE_SERIAL_LCD
77
77
#if defined(USE_SERIAL_LCD)
78
78
#include " LiquidCrystal_I2C.h" // Use an up to date library version, which has the init method
79
79
#elif !defined(USE_NO_LCD)
82
82
#endif
83
83
84
84
#if defined(USE_PARALLEL_LCD)
85
- #define DEBUG_BUTTON_PIN 11
86
- #endif
87
- #if !defined(DEBUG_BUTTON_PIN)
88
- # if defined(APPLICATION_PIN)
89
- #define DEBUG_BUTTON_PIN APPLICATION_PIN // if low, print timing for each received data set
90
- # else
85
+ #define DEBUG_BUTTON_PIN 11 // If low, print timing for each received data set
86
+ #define AUXILIARY_DEBUG_BUTTON_PIN 12 // Is set to low to enable using of a simple connector for enabling debug
87
+ #undef TONE_PIN
88
+ #define TONE_PIN 9 // Pin 4 is used by LCD
89
+ #else
91
90
#define DEBUG_BUTTON_PIN 6
92
- # endif
93
91
#endif
94
92
95
93
#if defined(USE_SERIAL_LCD) || defined(USE_PARALLEL_LCD)
102
100
#include " ADCUtils.hpp"
103
101
#define MILLIS_BETWEEN_VOLTAGE_PRINT 5000
104
102
#define LCD_VOLTAGE_START_INDEX 11
105
- uint32_t volatile sMillisOfLastVoltagePrint ;
106
- bool ProtocolStringOverwritesVoltage;
103
+ uint32_t volatile sMillisOfLastVoltagePrint = 0 ;
104
+ bool ProtocolStringOverwritesVoltage = false ;
107
105
# endif
108
106
#define LCD_IR_COMMAND_START_INDEX 9
109
107
@@ -113,8 +111,8 @@ bool ProtocolStringOverwritesVoltage;
113
111
LiquidCrystal_I2C myLCD (0x27 , LCD_COLUMNS, LCD_ROWS); // set the LCD address to 0x27 for a 16 chars and 2 line display
114
112
#endif
115
113
#if defined(USE_PARALLEL_LCD)
116
- LiquidCrystal myLCD (4 , 5 , 6 , 7 , 8 , 9 );
117
- // LiquidCrystal myLCD(7, 8, 3, 4, 5, 6);
114
+ // LiquidCrystal myLCD(4, 5, 6, 7, 8, 9);
115
+ LiquidCrystal myLCD (7 , 8 , 3 , 4 , 5 , 6 );
118
116
#endif
119
117
120
118
void printIRResultOnLCD ();
@@ -124,6 +122,10 @@ void printSpaces(uint_fast8_t aNumberOfSpacesToPrint);
124
122
void setup () {
125
123
#if FLASHEND >= 0x3FFF // For 16k flash or more, like ATtiny1604. Code does not fit in program memory of ATtiny85 etc.
126
124
pinMode (DEBUG_BUTTON_PIN, INPUT_PULLUP);
125
+ # if defined(AUXILIARY_DEBUG_BUTTON_PIN)
126
+ pinMode (AUXILIARY_DEBUG_BUTTON_PIN, OUTPUT);
127
+ digitalWrite (AUXILIARY_DEBUG_BUTTON_PIN, LOW); // To use a simple connector to enable debug
128
+ # endif
127
129
#endif
128
130
129
131
Serial.begin (115200 );
@@ -150,6 +152,7 @@ void setup() {
150
152
#endif
151
153
152
154
#if FLASHEND >= 0x3FFF // For 16k flash or more, like ATtiny1604. Code does not fit in program memory of ATtiny85 etc.
155
+ Serial.println ();
153
156
Serial.print (F (" Debug button pin is " ));
154
157
Serial.println (DEBUG_BUTTON_PIN);
155
158
@@ -195,16 +198,37 @@ void loop() {
195
198
if (IrReceiver.decodedIRData .flags & IRDATA_FLAGS_WAS_OVERFLOW) {
196
199
Serial.println (F (" Overflow detected" ));
197
200
Serial.println (F (" Try to increase the \" RAW_BUFFER_LENGTH\" value of " STR (RAW_BUFFER_LENGTH) " in " __FILE__));
201
+ #if defined(USE_LCD)
202
+ myLCD.setCursor (0 , 0 );
203
+ myLCD.print (F (" Overflow " ));
204
+ #endif
205
+
198
206
// see also https://github.com/Arduino-IRremote/Arduino-IRremote#compile-options--macros-for-this-library
199
207
200
208
} else {
209
+ // play tone
210
+ auto tStartMillis = millis ();
211
+ IrReceiver.stop ();
212
+ tone (TONE_PIN, 2200 );
213
+
201
214
// Print a short summary of received data
202
215
IrReceiver.printIRResultShort (&Serial);
203
216
204
217
if (IrReceiver.decodedIRData .protocol == UNKNOWN || digitalRead (DEBUG_BUTTON_PIN) == LOW) {
205
- // We have an unknown protocol, print more info
218
+ // Print more info
219
+ IrReceiver.printIRSendUsage (&Serial);
206
220
IrReceiver.printIRResultRawFormatted (&Serial, false );
207
221
}
222
+
223
+ // Guarantee at least 5 millis for tone. decode starts 5 millis (RECORD_GAP_MICROS) after end of frame
224
+ // so here we are 10 millis after end of frame. Sony20 has only a 12 ms repeat gap.
225
+ while ((millis () - tStartMillis) < 5 )
226
+ ;
227
+ noTone (TONE_PIN);
228
+
229
+ // Restore IR timer. millis() - tStartMillis to compensate for stop of receiver. This enables a correct gap measurement.
230
+ IrReceiver.startWithTicksToAdd ((millis () - tStartMillis) * (MICROS_IN_ONE_MILLI / MICROS_PER_TICK));
231
+
208
232
#if defined(USE_LCD)
209
233
printIRResultOnLCD ();
210
234
#endif
@@ -217,7 +241,7 @@ void loop() {
217
241
IrReceiver.resume ();
218
242
} // if (IrReceiver.decode())
219
243
220
- #if defined(USE_LCD) && defined(__AVR__) && defined(ADCSRA) && defined(ADATE )
244
+ #if defined(USE_LCD) && defined(ADC_UTILS_ARE_AVAILABLE )
221
245
// Periodically print VCC
222
246
if (!ProtocolStringOverwritesVoltage && millis () - sMillisOfLastVoltagePrint > MILLIS_BETWEEN_VOLTAGE_PRINT) {
223
247
/*
@@ -227,7 +251,8 @@ void loop() {
227
251
uint16_t tVCC = getVCCVoltageMillivoltSimple ();
228
252
char tVoltageString[5 ];
229
253
dtostrf (tVCC / 1000.0 , 4 , 2 , tVoltageString);
230
- myLCD.setCursor (LCD_VOLTAGE_START_INDEX, 0 );
254
+ myLCD.setCursor (LCD_VOLTAGE_START_INDEX - 1 , 0 );
255
+ myLCD.print (' ' );
231
256
myLCD.print (tVoltageString);
232
257
myLCD.print (' V' );
233
258
}
@@ -345,6 +370,7 @@ void printIRResultOnLCD() {
345
370
#endif // defined(USE_LCD)
346
371
}
347
372
373
+ #if defined(USE_LCD)
348
374
size_t printHex (uint16_t aHexByteValue) {
349
375
myLCD.print (F (" 0x" ));
350
376
size_t tPrintSize = 2 ;
@@ -360,3 +386,4 @@ void printSpaces(uint_fast8_t aNumberOfSpacesToPrint) {
360
386
myLCD.print (' ' );
361
387
}
362
388
}
389
+ #endif
0 commit comments