// This is a 'while' test. It appears that the while statement, locks out timer ISR
// If line 18 and line 19 is deleted, while loop freezes. If 18 or 19 is
// enabled, while loop runs ok.
#include <TimerOne.h>
int tick;
//------------------------------------------------------------------------------------------------------
void setup() {
Serial.begin(115200);
Timer1.initialize(2000);
Timer1.attachInterrupt(tick_time);
}
//-----------------------------------------------------------------------------------------------------------------
void loop() {
Serial.println("16 loop start");
while(tick < 20) { // tick = 20 should NEVER be printed !!
// interrupts(); // If this and next line are both deleted
Serial.print("19 tick=");Serial.println(tick); // 'While' loop does not run.
}
Serial.println("21 here after while loop completion");
tick = 0;
}
//------------------------------------------------------------------------------------------------------------------------
void tick_time() {
tick++;
}
//------------------------------------------------------------------------------------------------------------------------
I have used while loops successfully for years, but not with a timer ISR.