11/*
2- * AllProtocols .cpp
2+ * AllProtocolsOnLCD .cpp
33 *
4- * Modified ReceiveDemo.cpp with additional LCD output.
4+ * Modified ReceiveDemo.cpp with additional 1602 LCD output.
55 * If debug button is pressed (pin connected to ground) a long output is generated.
66 *
77 * This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
7373 * because of the long lasting serial communication.
7474 */
7575// #define USE_NO_LCD
76- #define USE_SERIAL_LCD
76+ // #define USE_SERIAL_LCD
7777#if defined(USE_SERIAL_LCD)
7878#include " LiquidCrystal_I2C.h" // Use an up to date library version, which has the init method
7979#elif !defined(USE_NO_LCD)
8282#endif
8383
8484#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
9190#define DEBUG_BUTTON_PIN 6
92- # endif
9391#endif
9492
9593#if defined(USE_SERIAL_LCD) || defined(USE_PARALLEL_LCD)
102100#include " ADCUtils.hpp"
103101#define MILLIS_BETWEEN_VOLTAGE_PRINT 5000
104102#define LCD_VOLTAGE_START_INDEX 11
105- uint32_t volatile sMillisOfLastVoltagePrint ;
106- bool ProtocolStringOverwritesVoltage;
103+ uint32_t volatile sMillisOfLastVoltagePrint = 0 ;
104+ bool ProtocolStringOverwritesVoltage = false ;
107105# endif
108106#define LCD_IR_COMMAND_START_INDEX 9
109107
@@ -113,8 +111,8 @@ bool ProtocolStringOverwritesVoltage;
113111LiquidCrystal_I2C myLCD (0x27 , LCD_COLUMNS, LCD_ROWS); // set the LCD address to 0x27 for a 16 chars and 2 line display
114112#endif
115113#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 );
118116#endif
119117
120118void printIRResultOnLCD ();
@@ -124,6 +122,10 @@ void printSpaces(uint_fast8_t aNumberOfSpacesToPrint);
124122void setup () {
125123#if FLASHEND >= 0x3FFF // For 16k flash or more, like ATtiny1604. Code does not fit in program memory of ATtiny85 etc.
126124 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
127129#endif
128130
129131 Serial.begin (115200 );
@@ -150,6 +152,7 @@ void setup() {
150152#endif
151153
152154#if FLASHEND >= 0x3FFF // For 16k flash or more, like ATtiny1604. Code does not fit in program memory of ATtiny85 etc.
155+ Serial.println ();
153156 Serial.print (F (" Debug button pin is " ));
154157 Serial.println (DEBUG_BUTTON_PIN);
155158
@@ -195,16 +198,37 @@ void loop() {
195198 if (IrReceiver.decodedIRData .flags & IRDATA_FLAGS_WAS_OVERFLOW) {
196199 Serial.println (F (" Overflow detected" ));
197200 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+
198206 // see also https://github.com/Arduino-IRremote/Arduino-IRremote#compile-options--macros-for-this-library
199207
200208 } else {
209+ // play tone
210+ auto tStartMillis = millis ();
211+ IrReceiver.stop ();
212+ tone (TONE_PIN, 2200 );
213+
201214 // Print a short summary of received data
202215 IrReceiver.printIRResultShort (&Serial);
203216
204217 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);
206220 IrReceiver.printIRResultRawFormatted (&Serial, false );
207221 }
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+
208232#if defined(USE_LCD)
209233 printIRResultOnLCD ();
210234#endif
@@ -217,7 +241,7 @@ void loop() {
217241 IrReceiver.resume ();
218242 } // if (IrReceiver.decode())
219243
220- #if defined(USE_LCD) && defined(__AVR__) && defined(ADCSRA) && defined(ADATE )
244+ #if defined(USE_LCD) && defined(ADC_UTILS_ARE_AVAILABLE )
221245 // Periodically print VCC
222246 if (!ProtocolStringOverwritesVoltage && millis () - sMillisOfLastVoltagePrint > MILLIS_BETWEEN_VOLTAGE_PRINT) {
223247 /*
@@ -227,7 +251,8 @@ void loop() {
227251 uint16_t tVCC = getVCCVoltageMillivoltSimple ();
228252 char tVoltageString[5 ];
229253 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 (' ' );
231256 myLCD.print (tVoltageString);
232257 myLCD.print (' V' );
233258 }
@@ -345,6 +370,7 @@ void printIRResultOnLCD() {
345370#endif // defined(USE_LCD)
346371}
347372
373+ #if defined(USE_LCD)
348374size_t printHex (uint16_t aHexByteValue) {
349375 myLCD.print (F (" 0x" ));
350376 size_t tPrintSize = 2 ;
@@ -360,3 +386,4 @@ void printSpaces(uint_fast8_t aNumberOfSpacesToPrint) {
360386 myLCD.print (' ' );
361387 }
362388}
389+ #endif
0 commit comments