I have an arduino where I looking for an input event then do something. Unfortunately this input event can occur like 200 times and I only care about the first notification. Since I have a DS1302 timer handy in the circuit already for other purposes I was thinking using the minutes reading out of this to squelch this event.
Here is the code I come up with:
if (digitalRead(sensor_event)==HIGH)
{
if (RTC.read(tm)) {
if(time_set)
{
if (tm.Minute > time_pushed+5)
time_set=0; // Unlock
}
else
{
if (tm.Minute >= 55)
time_pushed=0;
else
time_pushed=tm.Minute; // Set global volatile min value
print("Sensor event");
time_set=1;
}
}
}
About the seconds and hours I don't care all I need is if this event is detected then go ahead with a function and put it on a 5 minutes hold before checking it again.
The small issue here is the minute overflow. For example if the minute is just at 56 when this happens the time_pushed would be set to 56 then the time_pushed+5 would give 61 (which of course is never reached).
Is there a better way to code this? What is the name of this time issue I having to ignore an event until x minutes? What I found for this was mostly debounce but I'm sure this has to be handled by others sometimes too.
Thanks