@@ -70,51 +70,71 @@ Timer3, Timer4 and Timer5 are supported for Arduino Maga boards.
7070How to use:
7171
7272```
73- #include "TimerInterrupt.h"
73+ //These define's must be placed at the beginning before #include "TimerInterrupt.h"
74+ #define TIMER_INTERRUPT_DEBUG 0
7475
75- #define TIMER1_DURATION_MS 5000L
76- #define TIMER1_FREQUENCY 10
77- #define TIMER1_INTERVAL_MS (1000 / TIMER1_FREQUENCY)
76+ #define USE_TIMER_1 true
77+ #define USE_TIMER_2 true
78+ #define USE_TIMER_3 false
79+ #define USE_TIMER_4 false
80+ #define USE_TIMER_5 false
7881
79- #define TIMER2_DURATION_MS 20000L
80- #define TIMER2_FREQUENCY 100
81- #define TIMER2_INTERVAL_MS (1000 / TIMER2_FREQUENCY)
82+ #include "TimerInterrupt.h"
8283
83- void TimerHandler1()
84+ void TimerHandler1(void )
8485{
85- // your readSensor() function will be called @ TIMER1_FREQUENCY = 10 Hz or every 100ms
86- // This uses hardware timer interrupt and still works even if other functions is blocking.
87- // Functions using normal software timers, relying on loop() and calling millis(), won't work
88- // if the loop() or setup() is blocked by certain operation.
89- readSensor();
86+ static bool toggle1 = false;
87+ static bool started = false;
88+
89+ if (!started)
90+ {
91+ started = true;
92+ pinMode(LED_BUILTIN, OUTPUT);
93+ }
94+
95+ //timer interrupt toggles pin LED_BUILTIN
96+ digitalWrite(LED_BUILTIN, toggle1);
97+ toggle1 = !toggle1;
9098}
9199
92- void TimerHandler2()
100+ void TimerHandler2(void )
93101{
94- // your_Function() will be called @ TIMER2_FREQUENCY = 100Hz or every 10ms.
95- your_Function();
102+ static bool toggle2 = false;
103+ static bool started = false;
104+
105+ if (!started)
106+ {
107+ started = true;
108+ pinMode(A0, OUTPUT);
109+ }
110+
111+ //timer interrupt toggles outputPin
112+ digitalWrite(A0, toggle2);
113+ toggle2 = !toggle2;
96114}
97115
116+ #define TIMER1_INTERVAL_MS 1000
117+
118+ #define TIMER2_INTERVAL_MS 2000
119+
98120void setup()
99121{
100122 Serial.begin(115200);
101-
102- ...
103-
104- // Timer0 is used for micros(), millis(), delay(), etc and can't be used
123+ Serial.println("\nStarting");
124+
105125 // Select Timer 1-2 for UNO, 0-5 for MEGA
106- // Timer 2 is 8-bit timer, only for higher frequency
126+ // Timer 2 is 8-bit timer, only for higher frequency
107127 ITimer1.init();
108128
109129 // Using ATmega328 used in UNO => 16MHz CPU clock ,
110- // For 16-bit timer 1, 3, 4 and 5, set frequency from 0.2385 to some KHz
111- // For 8-bit timer 2 (prescaler up to 1024, set frequency from 61.5Hz to some KHz
112- if (ITimer1.attachInterrupt(TIMER1_FREQUENCY, TimerHandler1))
130+
131+ if (ITimer1.attachInterruptInterval(TIMER1_INTERVAL_MS, TimerHandler1))
113132 Serial.println("Starting ITimer1 OK, millis() = " + String(millis()));
114133 else
115134 Serial.println("Can't set ITimer1. Select another freq. or timer");
116-
117- //Timer2
135+
136+ // Select Timer 1-2 for UNO, 0-5 for MEGA
137+ // Timer 2 is 8-bit timer, only for higher frequency
118138 ITimer2.init();
119139
120140 if (ITimer2.attachInterruptInterval(TIMER2_INTERVAL_MS, TimerHandler2))
@@ -125,13 +145,26 @@ void setup()
125145
126146void loop()
127147{
148+
128149}
129150
130151```
131152## TO DO
132153
1331541 . Similar library for ESP8266 and ESP32
134- 2 . Longer Interval for timers.
155+
156+
157+ ## DONE
158+
159+ For current version v1.0.1
160+
161+ 1 . Longer Interval for timers.
162+ 2 . Reduce code size if use less timers. Eliminate compiler warnings.
163+ 3 . Now supporting complex object pointer-type argument.
164+ 4 . Fix some bugs in v1.0.0
165+ 5 . Add more examples.
166+
167+
135168
136169## Contributing
137170If you want to contribute to this project:
0 commit comments