Skip to content

Commit d1a290e

Browse files
committed
Examples tone delay handling
1 parent 9369fbe commit d1a290e

File tree

17 files changed

+332
-263
lines changed

17 files changed

+332
-263
lines changed

.github/workflows/LibraryBuild.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,14 @@ jobs:
149149
- arduino-boards-fqbn: megaTinyCore:megaavr:atxy4:chip=1604,clock=16internal
150150
arduino-platform: megaTinyCore:megaavr@2.5.11 # The current 2.6.0 is broken see https://github.com/SpenceKonde/megaTinyCore/issues/805
151151
platform-url: http://drazzy.com/package_drazzy.com_index.json
152+
sketches-exclude: AllProtocolsOnLCD
152153
build-properties: # the flags were put in compiler.cpp.extra_flags
153154
IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=100
154155

155156
- arduino-boards-fqbn: megaTinyCore:megaavr:atxy7:chip=3217,clock=16internal
156157
arduino-platform: megaTinyCore:megaavr@2.5.11
157158
platform-url: http://drazzy.com/package_drazzy.com_index.json
159+
sketches-exclude: AllProtocolsOnLCD
158160
build-properties: # the flags were put in compiler.cpp.extra_flags
159161
IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=100
160162

@@ -236,7 +238,7 @@ jobs:
236238

237239
- arduino-boards-fqbn: Seeeduino:samd:seeed_XIAO_m0:usbstack=arduino,debug=off,sercom4=include
238240
platform-url: https://files.seeedstudio.com/arduino/package_seeeduino_boards_index.json
239-
sketches-exclude: AllProtocols
241+
sketches-exclude: AllProtocolsOnLCD
240242
build-properties: # the flags were put in compiler.cpp.extra_flags
241243
IRremoteExtensionTest: -DRAW_BUFFER_LENGTH=700
242244
All: -DRAW_BUFFER_LENGTH=300

README.md

Lines changed: 35 additions & 31 deletions
Large diffs are not rendered by default.

examples/AllProtocols/ADCUtils.h renamed to examples/AllProtocolsOnLCD/ADCUtils.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#define _ADC_UTILS_H
2626

2727
#if defined(__AVR__) && defined(ADCSRA) && defined(ADATE) && (!defined(__AVR_ATmega4809__))
28+
#define ADC_UTILS_ARE_AVAILABLE
2829
#include <Arduino.h>
2930

3031
// PRESCALE4 => 13 * 4 = 52 microseconds per ADC conversion at 1 MHz Clock => 19,2 kHz

examples/AllProtocols/ADCUtils.hpp renamed to examples/AllProtocolsOnLCD/ADCUtils.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#define _ADC_UTILS_HPP
2727

2828
#include "ADCUtils.h"
29-
#if defined(__AVR__) && defined(ADCSRA) && defined(ADATE) && (!defined(__AVR_ATmega4809__))
29+
#if defined(ADC_UTILS_ARE_AVAILABLE)
3030

3131
#if !defined(STR_HELPER)
3232
#define STR_HELPER(x) #x

examples/AllProtocols/AllProtocols.ino renamed to examples/AllProtocolsOnLCD/AllProtocolsOnLCD.ino

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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.
@@ -73,7 +73,7 @@
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)
@@ -82,14 +82,12 @@
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)
@@ -102,8 +100,8 @@
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;
113111
LiquidCrystal_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

120118
void printIRResultOnLCD();
@@ -124,6 +122,10 @@ void printSpaces(uint_fast8_t aNumberOfSpacesToPrint);
124122
void 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)
348374
size_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

Comments
 (0)