Dear All,
I am fairly new at Arduino & am learning through online tutorials. I have been trying to use Timers & have come across TimerOne library. It is working well for me except the fact that every time I use Timer1.restart(), the timer restarts but also gives an interrupt.
I want it to simply start counting time from 0 when an input goes high & only execute the interrupt when the timer overflows, not when it restarts. Is there a way this can be done? My basic code is as shown -
#include <TimerOne.h>
int interrupt = 2;
volatile int count = 0;
void setup() {
Serial.begin(9600);
Timer1.initialize(4000000);
Timer1.attachInterrupt(Timer);
pinMode(interrupt, INPUT_PULLUP);
attachInterrupt(0, interrupt0, RISING);
}
void loop() {
}
void interrupt0()
{
Serial.println("input");
Timer1.restart();
}
void Timer()
{
Serial.println("Time up");
count++;
Serial.println(count);
}
When I simulated the same on wokwi.com, using the same TimerOne library in the simulator, it did not execute the interrupt when the timer was restarted. It only happens when I am using physical hardware Arduino UNO. Thank you in advance.