Thank you for helping. I have created small isolated program to simulate and I think I got it. I just hope that it would survive millis rollover. Here is the code:
long unsigned prevTime[] = {0UL, 0UL, 0UL}; //previous times for batteries
long unsigned waitTime[] = {5000UL, 8000UL, 22500UL}; //simulated times for batteries
int wt[] = {0,0,0}; //flag for battery timer status {0 = timer not running, 1 = timer running}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
for(int x = 0; x <3; x++){
if(wt
- == 0){ //if timer is not runnig
prevTime
- = millis(); //get current value of millis
Serial.println("Curent millis: " + String(prevTime
wt
- = 1; //set timer to running
}
if(idleTime(x, waitTime
Serial.println("Time has passed for battery " + String(x));
}
}
}
bool idleTime(int y, unsigned long waitTime){
if( millis()- prevTime[y] >= waitTime){ //check if time defined has passed
wt[y] = 0; //reset timer flag to not running
return true;
}
return false;
}