Skip to content
This repository was archived by the owner on Jan 29, 2023. It is now read-only.

Commit d3afa31

Browse files
authored
v1.1.2
### Releases v1.1.2 1. Fix compiler warnings. 2. Optimize examples to reduce memory usage by using Flash String whenever possible. 3. Clean-up all compiler warnings possible. 4. Add Table of Contents
1 parent 9eff41b commit d3afa31

File tree

31 files changed

+790
-361
lines changed

31 files changed

+790
-361
lines changed

README.md

Lines changed: 223 additions & 111 deletions
Large diffs are not rendered by default.

examples/Argument_Complex/Argument_Complex.ino

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
If your data is multiple variables, such as an array and a count, usually interrupts need to be disabled
2323
or the entire sequence of your code which accesses the data.
2424
25-
Version: 1.1.0
25+
Version: 1.1.2
2626
2727
Version Modified By Date Comments
2828
------- ----------- ---------- -----------
@@ -31,9 +31,21 @@
3131
1.0.2 K.Hoang 28/11/2019 Permit up to 16 super-long-time, super-accurate ISR-based timers to avoid being blocked
3232
1.0.3 K.Hoang 01/12/2020 Add complex examples ISR_16_Timers_Array_Complex and ISR_16_Timers_Array_Complex
3333
1.1.1 K.Hoang 06/12/2020 Add example Change_Interval. Bump up version to sync with other TimerInterrupt Libraries
34+
1.1.2 K.Hoang 05/01/2021 Fix warnings. Optimize examples to reduce memory usage
3435
*****************************************************************************************************************************/
3536

36-
//These define's must be placed at the beginning before #include "TimerInterrupt.h"
37+
#if defined(__AVR_ATmega8__) || defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || \
38+
defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || \
39+
defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_NANO) || \
40+
defined(ARDUINO_AVR_MINI) || defined(ARDUINO_AVR_ETHERNET) || defined(ARDUINO_AVR_FIO) || defined(ARDUINO_AVR_BT) || \
41+
defined(ARDUINO_AVR_LILYPAD) || defined(ARDUINO_AVR_PRO) || defined(ARDUINO_AVR_NG) || defined(ARDUINO_AVR_UNO_WIFI_DEV_ED)
42+
43+
#else
44+
#error This is designed only for Arduino AVR board! Please check your Tools->Board setting.
45+
#endif
46+
47+
// These define's must be placed at the beginning before #include "TimerInterrupt.h"
48+
// Don't define TIMER_INTERRUPT_DEBUG > 0. Only for special ISR debugging only. Can hang the system.
3749
#define TIMER_INTERRUPT_DEBUG 0
3850

3951
#define USE_TIMER_1 true
@@ -67,15 +79,22 @@ void TimerHandler1(unsigned int outputPinsAddress)
6779
}
6880

6981
//timer interrupt toggles pins
70-
Serial.println("Toggle pin1 = " + String(((pinStruct *) outputPinsAddress)->Pin1) );
82+
#if (TIMER_INTERRUPT_DEBUG > 1)
83+
Serial.print("Toggle pin1 = "); Serial.println( ((pinStruct *) outputPinsAddress)->Pin1 );
84+
#endif
85+
7186
digitalWrite(((pinStruct *) outputPinsAddress)->Pin1, toggle1);
7287

73-
Serial.println("Read pin2 A0 (" + String(((pinStruct *) outputPinsAddress)->Pin2) + ") = " +
74-
String( digitalRead(((pinStruct *) outputPinsAddress)->Pin2) ? "HIGH" : "LOW" ) );
75-
76-
Serial.println("Read pin3 A1 (" + String(((pinStruct *) outputPinsAddress)->Pin3) + ") = " +
77-
String( digitalRead(((pinStruct *) outputPinsAddress)->Pin3) ? "HIGH" : "LOW" ) );
88+
#if (TIMER_INTERRUPT_DEBUG > 1)
89+
Serial.print("Read pin2 A0 ("); Serial.print(((pinStruct *) outputPinsAddress)->Pin2 );
90+
Serial.print(") = ");
91+
Serial.println(digitalRead(((pinStruct *) outputPinsAddress)->Pin2) ? "HIGH" : "LOW" );
7892

93+
Serial.print("Read pin3 A1 ("); Serial.print(((pinStruct *) outputPinsAddress)->Pin3 );
94+
Serial.print(") = ");
95+
Serial.println(digitalRead(((pinStruct *) outputPinsAddress)->Pin3) ? "HIGH" : "LOW" );
96+
#endif
97+
7998
toggle1 = !toggle1;
8099
}
81100

@@ -86,9 +105,9 @@ void setup()
86105
Serial.begin(115200);
87106
while (!Serial);
88107

89-
Serial.println("\nStarting Argument_Complex");
108+
Serial.println(F("\nStarting Argument_Complex on AVR"));
90109
Serial.println(TIMER_INTERRUPT_VERSION);
91-
Serial.println("CPU Frequency = " + String(F_CPU / 1000000) + " MHz");
110+
Serial.print(F("CPU Frequency = ")); Serial.print(F_CPU / 1000000); Serial.println(F(" MHz"));
92111

93112
// Timer0 is used for micros(), millis(), delay(), etc and can't be used
94113
// Select Timer 1-2 for UNO, 0-5 for MEGA
@@ -101,9 +120,11 @@ void setup()
101120
// For 8-bit timer 2 (prescaler up to 1024, set frequency from 61.5Hz to some KHz
102121

103122
if (ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS, TimerHandler1, (unsigned int) &myOutputPins))
104-
Serial.println("Starting ITimer1 OK, millis() = " + String(millis()));
123+
{
124+
Serial.print(F("Starting ITimer1 OK, millis() = ")); Serial.println(millis());
125+
}
105126
else
106-
Serial.println("Can't set ITimer1. Select another freq. or timer");
127+
Serial.println(F("Can't set ITimer1. Select another freq. or timer"));
107128
}
108129

109130
void loop()

examples/Argument_None/Argument_None.ino

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
If your data is multiple variables, such as an array and a count, usually interrupts need to be disabled
2323
or the entire sequence of your code which accesses the data.
2424
25-
Version: 1.1.0
25+
Version: 1.1.2
2626
2727
Version Modified By Date Comments
2828
------- ----------- ---------- -----------
@@ -31,8 +31,21 @@
3131
1.0.2 K.Hoang 28/11/2019 Permit up to 16 super-long-time, super-accurate ISR-based timers to avoid being blocked
3232
1.0.3 K.Hoang 01/12/2020 Add complex examples ISR_16_Timers_Array_Complex and ISR_16_Timers_Array_Complex
3333
1.1.1 K.Hoang 06/12/2020 Add example Change_Interval. Bump up version to sync with other TimerInterrupt Libraries
34+
1.1.2 K.Hoang 05/01/2021 Fix warnings. Optimize examples to reduce memory usage
3435
*****************************************************************************************************************************/
35-
//These define's must be placed at the beginning before #include "TimerInterrupt.h"
36+
37+
#if defined(__AVR_ATmega8__) || defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || \
38+
defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || \
39+
defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_NANO) || \
40+
defined(ARDUINO_AVR_MINI) || defined(ARDUINO_AVR_ETHERNET) || defined(ARDUINO_AVR_FIO) || defined(ARDUINO_AVR_BT) || \
41+
defined(ARDUINO_AVR_LILYPAD) || defined(ARDUINO_AVR_PRO) || defined(ARDUINO_AVR_NG) || defined(ARDUINO_AVR_UNO_WIFI_DEV_ED)
42+
43+
#else
44+
#error This is designed only for Arduino AVR board! Please check your Tools->Board setting.
45+
#endif
46+
47+
// These define's must be placed at the beginning before #include "TimerInterrupt.h"
48+
// Don't define TIMER_INTERRUPT_DEBUG > 0. Only for special ISR debugging only. Can hang the system.
3649
#define TIMER_INTERRUPT_DEBUG 0
3750

3851
#define USE_TIMER_1 true
@@ -84,9 +97,9 @@ void setup()
8497
Serial.begin(115200);
8598
while (!Serial);
8699

87-
Serial.println("\nStarting Argument_None");
100+
Serial.println(F("\nStarting Argument_None on AVR"));
88101
Serial.println(TIMER_INTERRUPT_VERSION);
89-
Serial.println("CPU Frequency = " + String(F_CPU / 1000000) + " MHz");
102+
Serial.print(F("CPU Frequency = ")); Serial.print(F_CPU / 1000000); Serial.println(F(" MHz"));
90103

91104
// Select Timer 1-2 for UNO, 0-5 for MEGA
92105
// Timer 2 is 8-bit timer, only for higher frequency
@@ -97,18 +110,22 @@ void setup()
97110
// For 8-bit timer 2 (prescaler up to 1024, set frequency from 61.5Hz to some KHz
98111

99112
if (ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS, TimerHandler1))
100-
Serial.println("Starting ITimer1 OK, millis() = " + String(millis()));
113+
{
114+
Serial.print(F("Starting ITimer1 OK, millis() = ")); Serial.println(millis());
115+
}
101116
else
102-
Serial.println("Can't set ITimer1. Select another freq. or timer");
117+
Serial.println(F("Can't set ITimer1. Select another freq. or timer"));
103118

104119
// Select Timer 1-2 for UNO, 0-5 for MEGA
105120
// Timer 2 is 8-bit timer, only for higher frequency
106121
ITimer2.init();
107122

108123
if (ITimer2.attachInterruptInterval(TIMER2_INTERVAL_MS, TimerHandler2))
109-
Serial.println("Starting ITimer2 OK, millis() = " + String(millis()));
124+
{
125+
Serial.print(F("Starting ITimer2 OK, millis() = ")); Serial.println(millis());
126+
}
110127
else
111-
Serial.println("Can't set ITimer2. Select another freq. or timer");
128+
Serial.println(F("Can't set ITimer2. Select another freq. or timer"));
112129
}
113130

114131
void loop()

examples/Argument_Simple/Argument_Simple.ino

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
If your data is multiple variables, such as an array and a count, usually interrupts need to be disabled
2323
or the entire sequence of your code which accesses the data.
2424
25-
Version: 1.1.0
25+
Version: 1.1.2
2626
2727
Version Modified By Date Comments
2828
------- ----------- ---------- -----------
@@ -31,8 +31,21 @@
3131
1.0.2 K.Hoang 28/11/2019 Permit up to 16 super-long-time, super-accurate ISR-based timers to avoid being blocked
3232
1.0.3 K.Hoang 01/12/2020 Add complex examples ISR_16_Timers_Array_Complex and ISR_16_Timers_Array_Complex
3333
1.1.1 K.Hoang 06/12/2020 Add example Change_Interval. Bump up version to sync with other TimerInterrupt Libraries
34+
1.1.2 K.Hoang 05/01/2021 Fix warnings. Optimize examples to reduce memory usage
3435
*****************************************************************************************************************************/
35-
//These define's must be placed at the beginning before #include "TimerInterrupt.h"
36+
37+
#if defined(__AVR_ATmega8__) || defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || \
38+
defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || \
39+
defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_NANO) || \
40+
defined(ARDUINO_AVR_MINI) || defined(ARDUINO_AVR_ETHERNET) || defined(ARDUINO_AVR_FIO) || defined(ARDUINO_AVR_BT) || \
41+
defined(ARDUINO_AVR_LILYPAD) || defined(ARDUINO_AVR_PRO) || defined(ARDUINO_AVR_NG) || defined(ARDUINO_AVR_UNO_WIFI_DEV_ED)
42+
43+
#else
44+
#error This is designed only for Arduino AVR board! Please check your Tools->Board setting.
45+
#endif
46+
47+
// These define's must be placed at the beginning before #include "TimerInterrupt.h"
48+
// Don't define TIMER_INTERRUPT_DEBUG > 0. Only for special ISR debugging only. Can hang the system.
3649
#define TIMER_INTERRUPT_DEBUG 0
3750

3851
#define USE_TIMER_1 true
@@ -57,8 +70,12 @@ void TimerHandler1(unsigned int outputPin = LED_BUILTIN)
5770
pinMode(outputPin, OUTPUT);
5871
}
5972

73+
#if (TIMER_INTERRUPT_DEBUG > 1)
6074
//timer interrupt toggles pin outputPin, default LED_BUILTIN
61-
Serial.println("pin1 = " + String(outputPin) + " address: " + String((uint32_t) &outputPin) );
75+
Serial.print("pin1 = "); Serial.print(outputPin);
76+
Serial.print(" address: "); Serial.println((uint32_t) &outputPin );
77+
#endif
78+
6279
digitalWrite(outputPin, toggle1);
6380
toggle1 = !toggle1;
6481
}
@@ -88,9 +105,9 @@ void setup()
88105
Serial.begin(115200);
89106
while (!Serial);
90107

91-
Serial.println("\nStarting Argument_Simple");
108+
Serial.println(F("\nStarting Argument_Simple on AVR"));
92109
Serial.println(TIMER_INTERRUPT_VERSION);
93-
Serial.println("CPU Frequency = " + String(F_CPU / 1000000) + " MHz");
110+
Serial.print(F("CPU Frequency = ")); Serial.print(F_CPU / 1000000); Serial.println(F(" MHz"));
94111

95112
// Timer0 is used for micros(), millis(), delay(), etc and can't be used
96113
// Select Timer 1-2 for UNO, 0-5 for MEGA
@@ -104,18 +121,29 @@ void setup()
104121

105122
if (ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS, TimerHandler1, outputPin1))
106123
{
107-
Serial.println("Starting ITimer1 OK, millis() = " + String(millis()));
108-
Serial.println("OutputPin1 = " + String(outputPin1) + ", address = " + String((uint32_t) &outputPin1) );
124+
Serial.print(F("Starting ITimer1 OK, millis() = ")); Serial.println(millis());
125+
126+
#if (TIMER_INTERRUPT_DEBUG > 1)
127+
Serial.print(F("OutputPin1 = ")); Serial.print(outputPin1);
128+
Serial.print(F(" address: ")); Serial.println((uint32_t) &outputPin1 );
129+
#endif
109130
}
110131
else
111-
Serial.println("Can't set ITimer1. Select another freq. or timer");
132+
Serial.println(F("Can't set ITimer1. Select another freq. or timer"));
112133

113134
ITimer2.init();
114135

115136
if (ITimer2.attachInterruptInterval(TIMER2_INTERVAL_MS, TimerHandler2, outputPin2))
116-
Serial.println("Starting ITimer2 OK, millis() = " + String(millis()));
137+
{
138+
Serial.print(F("Starting ITimer1 OK, millis() = ")); Serial.println(millis());
139+
140+
#if (TIMER_INTERRUPT_DEBUG > 1)
141+
Serial.print(F("OutputPin2 = ")); Serial.print(outputPin2);
142+
Serial.print(F(" address: ")); Serial.println((uint32_t) &outputPin2 );
143+
#endif
144+
}
117145
else
118-
Serial.println("Can't set ITimer2. Select another freq. or timer");
146+
Serial.println(F("Can't set ITimer2. Select another freq. or timer"));
119147
}
120148

121149
void loop()

examples/Change_Interval/Change_Interval.ino

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
If your data is multiple variables, such as an array and a count, usually interrupts need to be disabled
2323
or the entire sequence of your code which accesses the data.
2424
25-
Version: 1.1.0
25+
Version: 1.1.2
2626
2727
Version Modified By Date Comments
2828
------- ----------- ---------- -----------
@@ -31,6 +31,7 @@
3131
1.0.2 K.Hoang 28/11/2019 Permit up to 16 super-long-time, super-accurate ISR-based timers to avoid being blocked
3232
1.0.3 K.Hoang 01/12/2020 Add complex examples ISR_16_Timers_Array_Complex and ISR_16_Timers_Array_Complex
3333
1.1.1 K.Hoang 06/12/2020 Add example Change_Interval. Bump up version to sync with other TimerInterrupt Libraries
34+
1.1.2 K.Hoang 05/01/2021 Fix warnings. Optimize examples to reduce memory usage
3435
*****************************************************************************************************************************/
3536

3637
/*
@@ -45,7 +46,18 @@
4546
or the entire sequence of your code which accesses the data.
4647
*/
4748

48-
//These define's must be placed at the beginning before #include "TimerInterrupt.h"
49+
#if defined(__AVR_ATmega8__) || defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || \
50+
defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || \
51+
defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || defined(ARDUINO_AVR_UNO) || defined(ARDUINO_AVR_NANO) || \
52+
defined(ARDUINO_AVR_MINI) || defined(ARDUINO_AVR_ETHERNET) || defined(ARDUINO_AVR_FIO) || defined(ARDUINO_AVR_BT) || \
53+
defined(ARDUINO_AVR_LILYPAD) || defined(ARDUINO_AVR_PRO) || defined(ARDUINO_AVR_NG) || defined(ARDUINO_AVR_UNO_WIFI_DEV_ED)
54+
55+
#else
56+
#error This is designed only for Arduino AVR board! Please check your Tools->Board setting.
57+
#endif
58+
59+
// These define's must be placed at the beginning before #include "TimerInterrupt.h"
60+
// Don't define TIMER_INTERRUPT_DEBUG > 0. Only for special ISR debugging only. Can hang the system.
4961
#define TIMER_INTERRUPT_DEBUG 0
5062

5163
#define USE_TIMER_1 true
@@ -73,7 +85,9 @@ volatile uint32_t Timer2Count = 0;
7385

7486
void printResult(uint32_t currTime)
7587
{
76-
Serial.println("Time = " + String(currTime) + ", Timer1Count = " + String(Timer1Count) + ", Timer2Count = " + String(Timer2Count));
88+
Serial.print(F("Time = ")); Serial.print(currTime);
89+
Serial.print(F(", Timer1Count = ")); Serial.print(Timer1Count);
90+
Serial.print(F(", Timer2Count = ")); Serial.println(Timer2Count);
7791
}
7892

7993
void TimerHandler1(void)
@@ -108,9 +122,9 @@ void setup()
108122
Serial.begin(115200);
109123
while (!Serial);
110124

111-
Serial.println("\nStarting Change_Interval on AVR");
125+
Serial.println(F("\nStarting Change_Interval on AVR"));
112126
Serial.println(TIMER_INTERRUPT_VERSION);
113-
Serial.println("CPU Frequency = " + String(F_CPU / 1000000) + " MHz");
127+
Serial.print(F("CPU Frequency = ")); Serial.print(F_CPU / 1000000); Serial.println(F(" MHz"));
114128

115129

116130
// Select Timer 1-2 for UNO, 0-5 for MEGA
@@ -122,18 +136,22 @@ void setup()
122136
// For 8-bit timer 2 (prescaler up to 1024, set frequency from 61.5Hz to some KHz
123137

124138
if (ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS, TimerHandler1))
125-
Serial.println("Starting ITimer1 OK, millis() = " + String(millis()));
139+
{
140+
Serial.print(F("Starting ITimer1 OK, millis() = ")); Serial.println(millis());
141+
}
126142
else
127-
Serial.println("Can't set ITimer1. Select another freq. or timer");
143+
Serial.println(F("Can't set ITimer1. Select another freq. or timer"));
128144

129145
// Select Timer 1-2 for UNO, 0-5 for MEGA
130146
// Timer 2 is 8-bit timer, only for higher frequency
131147
ITimer2.init();
132148

133149
if (ITimer2.attachInterruptInterval(TIMER2_INTERVAL_MS, TimerHandler2))
134-
Serial.println("Starting ITimer2 OK, millis() = " + String(millis()));
150+
{
151+
Serial.print(F("Starting ITimer2 OK, millis() = ")); Serial.println(millis());
152+
}
135153
else
136-
Serial.println("Can't set ITimer2. Select another freq. or timer");
154+
Serial.println(F("Can't set ITimer2. Select another freq. or timer"));
137155
}
138156

139157
#define CHECK_INTERVAL_MS 10000L
@@ -164,8 +182,8 @@ void loop()
164182
ITimer1.setInterval(TIMER1_INTERVAL_MS * (multFactor + 1), TimerHandler1);
165183
ITimer2.setInterval(TIMER2_INTERVAL_MS * (multFactor + 1), TimerHandler2);
166184

167-
Serial.println("Changing Interval, Timer1 = " + String(TIMER1_INTERVAL_MS * (multFactor + 1)) +
168-
", Timer2 = " + String(TIMER2_INTERVAL_MS * (multFactor + 1)));
185+
Serial.print(F("Changing Interval, Timer1 = ")); Serial.print(TIMER1_INTERVAL_MS * (multFactor + 1));
186+
Serial.print(F(", Timer2 = ")); Serial.println(TIMER2_INTERVAL_MS * (multFactor + 1));
169187

170188
lastChangeTime = currTime;
171189
}

0 commit comments

Comments
 (0)