HI,
first of all I try to describe what your code-version posted in the first post tries to achieve:
every 40 seconds there should happen
if (analogueMeterPWM <= 127)
add 127 to the variable analogueMeterPWM
keep value of variable analogueMeterPWM for 200 milliseconds
after 200 milliseconds
reduce value of analogueMeterPWM to value before
if (analogueMeterPWM >= 127)
do the opposite: substract 127 from value of variable analogueMeterPWM
keep new value for 200 milliseconds
after 200 milliseconds increase value of analogueMeterPWM to value before
example with numbers:
39,999 seconds: analogueMeterPWM has value 20
40,000 seconds: analogueMeterPWM is set to 147
40,001 seconds: analogueMeterPWM is set to 147
40,002 seconds: analogueMeterPWM is set to 147
...
40,199 seconds: analogueMeterPWM is set to 147
40,200 second: analogueMeterPWM is set to 20
...
80,200 second: analogueMeterPWM is set to 20
80,200 seconds: analogueMeterPWM is set to 147
80,201 seconds: analogueMeterPWM is set to 147
80,202 seconds: analogueMeterPWM is set to 147
...
80,399 seconds: analogueMeterPWM is set to 147
80,400 seconds: analogueMeterPWM is set to 20
that's what you seem to try to code
Now if your code should not be blocked from running but instead should run through its loop
even with the value of analogueMeterPWM beeing increased/decreased temporarily for 200 milliseconds
this can be coded by additional timers and boolean-flag variables.
instead of calling a blocking delay() you set a boolean flag
I will call this variable "Change_analogueMeterPWM"
// define as global variables
boolean Change_analogueMeterPWM = false;
unsigned long analogueMeterPWM_Timer;
if (millis() - timerD >= 40000) { // execute the code below every 40 seconds
// "!" is the logical not-operator
if ( (analogueMeterPWM <= 127) && (!Change_analogueMeterPWM) { // if increase-pulse is not yet started
Change_analogueMeterPWM = true; // set flag that indicates increase-pulse HAS start
analogueMeterPWM_Timer = millis(); // setup timer-variable for 200msec-"pulse"
analogueMeterPWM = analogueMeterPWM + 127; // increase value
analogWrite(analogueMeter, analogueMeterPWM);
}
if (Change_analogueMeterPWM) { // if increase-pulse HAS started
if ( analogueMeterPWM_Timer - millis() >= 200) { // keep track of time passed by and if 200 milliseconds are over
Change_analogueMeterPWM = false; // set flag back to false
analogueMeterPWM = analogueMeterPWM - 127; // decrease value again
analogWrite(analogueMeter, analogueMeterPWM);
timerD = millis(); // update TimerD to start new 40-seconds cycle
}
}
}
by the way you should rename your timers TimerA, TimerB, TimerC etc. with selfexplaining names.
Each timer-variable has a certain purpose and the name of the variable should bring that purpose to the point.
Through the appendix "_timer" you still can indicate it is a variable for timing.
like my example "analogueMeterPWM_Timer"
I developed the habit of thinking 2 to 5 minutes about a meaningful and selfexplaining name for each variable.
You might think you don't want to invest that time. I made the experience that it saved me a lot of time later
as I don't have to jump in the code up and down "what was TimerD? used for???
If the name is selfexplaining you just read the code right where you are and your done.
best regards Stefan