cannot seem to find any code that uses interrupts for different on/off settings. Using delay is not recommended for this type of application require interrupts within operating loop so how do you set variable on of times of outputs
Hi.
I’m not sure that I understood your question.
Can you try to provide more details or explain in a different way?
Regards,
Sara
I think I have the same problem. – We would encourage a sample of 2 or more interrupt timers in parallel.
So a sample project like:
Unit 6 – ESP32 with PIR Motion Sensor: Interrupts and Timers
I am struggling with two timers in parallel:
// Timer Interrupt
hw_timer_t *timer1M = NULL;
void IRAM_ATTR onTimer1M()
{
// ISR
timer1M_trigger = TRUE;
}
hw_timer_t *timer5M = NULL;
void IRAM_ATTR onTimer5M()
{
// ISR
timer5M_trigger = TRUE;
}// Timer 1 min
timer1M = timerBegin(0, 80, true);
timerAttachInterrupt(timer1M, &onTimer1M, true);
timerAlarmWrite(timer1M, 60000000, true);
digitalWrite(LED, !digitalRead(LED));
timerAlarmEnable(timer1M);
// Timer 5 min
timer5M = timerBegin(0, 80, true);
timerAttachInterrupt(timer5M, &onTimer5M, true);
timerAlarmWrite(timer5M, 60000005, true);
timerAlarmEnable(timer5M);
(Please note: Timer values and prescaler values are not 1 and 5 minutes, as I am still experimenting.)
What is happening? – Timer1 fires correctly, but the implementation for the 2nd timer seems to be wrong.
A sound sample might help us all here.
Happy hacking’!
Hi.
At the moment, we don’t have any examples about that.
Have you taken a look at this library? https://github.com/philbowles/H4
It seems to provide functions for multiple timers. Take a look at its most simple example: https://github.com/philbowles/H4/blob/master/examples/multiblink/multiblink.ino
Does this help?
I’ll add that subject to my list of future tutorials.
Regards,
Sara