You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
intFunc = userFunc; // User's function to call when there's a timer event.
245
-
timer_setup(); // Configure the timer interrupt.
246
-
247
-
#if defined (__AVR_ATmega32U4__) // Use Timer4 for ATmega32U4 (Teensy/Leonardo).
248
-
OCR4C = min((frequency>>2) - 1, 255); // Every count is 4uS, so divide by 4 (bitwise shift right 2) subtract one, then make sure we don't go over 255 limit.
249
-
TIMSK4 = (1<<TOIE4); // Enable Timer4 interrupt.
250
-
#elif defined (__arm__) && defined (TEENSYDUINO) // Timer for Teensy 3.x
251
-
itimer.begin(userFunc, frequency); // Really simple on the Teensy 3.x, calls userFunc every 'frequency' uS.
252
-
#else
253
-
OCR2A = min((frequency>>2) - 1, 255); // Every count is 4uS, so divide by 4 (bitwise shift right 2) subtract one, then make sure we don't go over 255 limit.
#if defined (__AVR_ATmega32U4__) // Use Timer4 for ATmega32U4 (Teensy/Leonardo).
294
-
timer_stop(); // Disable Timer4 interrupt.
295
-
TCCR4A = TCCR4C = TCCR4D = TCCR4E = 0;
296
-
TCCR4B = (1<<CS42) | (1<<CS41) | (1<<CS40) | (1<<PSR4); // Set Timer4 prescaler to 64 (4uS/count, 4uS-1020uS range).
297
-
TIFR4 = (1<<TOV4);
298
-
TCNT4 = 0; // Reset Timer4 counter.
299
-
#elif defined (__AVR_ATmega8__) || defined (__AVR_ATmega16__) || defined (__AVR_ATmega32__) || defined (__AVR_ATmega8535__) // Alternate timer commands for certain microcontrollers.
300
-
timer_stop(); // Disable Timer2 interrupt.
301
-
ASSR &= ~(1<<AS2); // Set clock, not pin.
302
-
TCCR2 = (1<<WGM21 | 1<<CS22); // Set Timer2 to CTC mode, prescaler to 64 (4uS/count, 4uS-1020uS range).
303
-
TCNT2 = 0; // Reset Timer2 counter.
304
-
#elif defined (__arm__) && defined (TEENSYDUINO)
305
-
timer_stop(); // Stop the timer.
306
-
#else
307
-
timer_stop(); // Disable Timer2 interrupt.
308
-
ASSR &= ~(1<<AS2); // Set clock, not pin.
309
-
TCCR2A = (1<<WGM21); // Set Timer2 to CTC mode.
310
-
TCCR2B = (1<<CS22); // Set Timer2 prescaler to 64 (4uS/count, 4uS-1020uS range).
311
-
TCNT2 = 0; // Reset Timer2 counter.
312
-
#endif
313
-
}
314
-
315
-
316
-
voidNewPingESP8266::timer_ms_cntdwn() {
317
-
if (!_ms_cnt--) { // Count down till we reach zero.
318
-
intFunc2(); // Scheduled time reached, run the main timer event function.
319
-
_ms_cnt = _ms_cnt_reset; // Reset the ms timer.
320
-
}
321
-
}
322
-
323
-
#if defined (__AVR_ATmega32U4__) // Use Timer4 for ATmega32U4 (Teensy/Leonardo).
324
-
ISR(TIMER4_OVF_vect) {
325
-
intFunc(); // Call wrapped function.
326
-
}
327
-
#elif defined (__AVR_ATmega8__) || defined (__AVR_ATmega16__) || defined (__AVR_ATmega32__) || defined (__AVR_ATmega8535__) // Alternate timer commands for certain microcontrollers.
Copy file name to clipboardexpand all lines: NewPingESP8266.h
-21
Original file line number
Diff line number
Diff line change
@@ -150,7 +150,6 @@
150
150
#defineONE_PIN_ENABLEDtrue// Set to "false" to disable one pin mode which saves around 14-26 bytes of binary size. Default=true
151
151
#defineROUNDING_ENABLEDfalse// Set to "true" to enable distance rounding which also adds 64 bytes to binary size. Default=false
152
152
#defineURM37_ENABLEDfalse// Set to "true" to enable support for the URM37 sensor in PWM mode. Default=false
153
-
#defineTIMER_ENABLEDtrue// Set to "false" to disable the timer ISR (if getting "__vector_7" compile errors set this to false). Default=true
154
153
155
154
// Probably shouldn't change these values unless you really know what you're doing.
156
155
#defineNO_ECHO0// Value returned if there's no ping echo within the specified MAX_SENSOR_DISTANCE or max_cm_distance. Default=0
@@ -181,19 +180,11 @@
181
180
#definePING_OVERHEAD1
182
181
#undef PING_TIMER_OVERHEAD
183
182
#definePING_TIMER_OVERHEAD1
184
-
#undef TIMER_ENABLED
185
-
#defineTIMER_ENABLEDfalse
186
183
#defineDO_BITWISEfalse
187
184
#else
188
185
#defineDO_BITWISEtrue
189
186
#endif
190
187
191
-
// Disable the timer interrupts when using ATmega128 and all ATtiny microcontrollers.
192
-
#if defined (__AVR_ATmega128__) || defined (__AVR_ATtiny24__) || defined (__AVR_ATtiny44__) || defined (__AVR_ATtiny84__) || defined (__AVR_ATtiny25__) || defined (__AVR_ATtiny45__) || defined (__AVR_ATtiny85__) || defined (__AVR_ATtiny261__) || defined (__AVR_ATtiny461__) || defined (__AVR_ATtiny861__) || defined (__AVR_ATtiny43U__)
193
-
#undef TIMER_ENABLED
194
-
#defineTIMER_ENABLEDfalse
195
-
#endif
196
-
197
188
// Define timers when using ATmega8, ATmega16, ATmega32 and ATmega8535 microcontrollers.
198
189
#if defined (__AVR_ATmega8__) || defined (__AVR_ATmega16__) || defined (__AVR_ATmega32__) || defined (__AVR_ATmega8535__)
199
190
#defineOCR2A OCR2
@@ -210,22 +201,10 @@ class NewPingESP8266 {
210
201
unsignedlongping_median(uint32_t it = 5, unsignedint max_cm_distance = 0);
0 commit comments