I suspect the problem is that you're overflowing the bounds of one of those arrays. Here is one place you do it - I haven't checked for others:
for (int i = 0; i <= MaxTimers; i++)
The '<=' should be a '<'.
I also noticed this code:
int DiffMillis;
unsigned long ActualMills = millis();
if (LastTimeLoop > ActualMills)
{
// questo ? il valore massimo di millisecondi :4,294,967,295
DiffMillis = 4294967295 - LastTimeLoop + ActualMills;
}
else
{
DiffMillis = ActualMills - LastTimeLoop;
}
Please don't do that. I don't know whether it actually copes correctly with timer overflow, but it's a horrible way to do it. If you want to know how many milliseconds have elapsed between two calls to millis(), do it like this:
unsigned long startTime = millis();
// do stuff
unsigned long elapsed = millis() - startTime;
I assume you can generalise that approach to do whatever it is you're trying to do here. The important details in order for timer overflow to be handled correctly are:
- Use unsigned long
- Use subtraction not addition