How can I create Time interrupt that triggers after 2 minutes on uno
How can I create Time interrupt that triggers after 2 minutes on uno
I have not yet done the maths but possibly a 16bit timer with the pre-scaler set to max and the count to max, use an interrupt when it rolls over
you can also use a loop checking the time elapsed and then generate an interrupt or call a routine that does some event based on the elapsed time
What is the purpose of the timer, knowing this we will be able to give as better answer
I'm not familiar with the arduino, but microcontrollers have timers built in. So, I recommend reading about the timers in the arduino.
You can use the Millis() timer to check, and do whatever you want after the time reached.
You need to declare it as more than an int ( long will work)
I use a 30 second one in one of my sketches
int ButtonTimeout = 30000;
// Timeout if no button is pressed. Note wipe interval is lower than this. [30 seconds]
unsigned long ButtonPressTime = 0;
// Time the last button was pressed.
if (((millis()-ButtonPressTime) > ButtonTimeout) && (IntWipe == 1))
// 30 Sec timeout for no button press, but only after stopped, or 1 start.
{
IntWipe = 0;
LastWipeTime = 0;
WipeInterval = 0;
}
mark
@ARif you may use timer interrupt of atmega but it will change delay or some of pwm functionality...so be careful by doing this... as mills() and micros() concern will not work exactly like interrupt it is accurate but its polling....so if your code complexity is less then go ahead with mill() or micros()...