The code I want to add is the commented part. If I do that, I'm think the program will loop in my progress bar then will set the pin 13 HIGH. Thus the filling will be done after the progress bar is completed.
Thus, how to add the progress bar "for" loop and have it working together with the "remplissage" loop?
If you have a loop in a loop, the inner loop will execute each time the outer loop executes once. if you want both loops simultaneous, you cannot use for, as you cannot exit a for loop until the condition is met. Or, you can try to do both tasks within a single for loop.
Thanks for the reply. Unfortunately, you answered exactly what I did not want to read .
I'll rethink completely my first loop to include the progress bar to have a single "for" loop. With my noob level in in C++, it won't be easy.
Do you think I could create a progress bar function (containing the progress bar "for" loop) and call it where needed? Does it stop the other loop until the function is executed?
The processor can do only one task at a time, so if two processes are supposed to happen "at the same time", you have to share that time between them somehow.
You just have to implement your own sort of version of a for loop. Each portion will execute and increment the counter until the end condition is met. If both end conditions are met, 'done' never gets reset to false so the while() loop exits. With those delay()s in your code, this won't happen very fast but should give you the idea.
//Remplissage echantillon client
bool done = false;
int n = 1;
int z = 0;
while ( !done ) {
done = true;
if (n <= nombreBouteille)
{
Serial.print("remplissage bout n°:");////pour debug, a effacer
Serial.println(n);//pour debug, a effacer
Remplissage.setValue(n);
n++;
done = false;
}
if (z <= TempsAllumagePompel )
{
x = map(z, 0, TempsAllumagePompel, 0, 100);
j0.setValue(x);
z++;
done = false;
}
digitalWrite(13, HIGH);
delay(TempsAllumagePompel);
digitalWrite(13, LOW);
delay(1000);
}
Hi, @blh64, thanks for the code. i'll try that tomorrow.
I'm not familiar yet with C++ thus, these kind of ideas are not very evident for me. Maybe one day I would have come to that solution but after many many fails...
Note how each function runs very briefly and returns to loop() so the next one can be called. None of the functions tries to complete a task in one call. And there may be dozens of calls to a function before it is actually time for it to do anything.
Also note that there is no blocking FOR or WHILE loop.
I have more or less won.
First I wished my progress bar evolving with the delay but it is way too difficult for my level.
Thus I made the progress bar evolving with the number of the bottle I fill.
I'm glad to tell my project is done and working. Next steps are to create a nice enclosure and find a reliable and repeatable pump.
Here is the full code of the syrup dispenser I've made and the HMI file (remove .ino in the filename) for the nextion
Certainly not the state of the art in coding but for someone who, 12 months ago, was not knowing what is an arduino, it is not so bad.