Serial.print a duration

int temps_infusion = 10000 ;
int temps ;
void setup() {

Serial.begin(9600)

}

void loop() {

     unsigned long temps_aff = 0;
temps = millis();
 while(millis() < temps + temps_infusion){
        temps_aff = temps_aff + millis();
        Serial.print ("temps = ");
        Serial.print (temps_aff);
        Serial.print ('\n');
    }

What I want with this part of my code is to print on the screen the duration which has passed since the while started, NOT the millis(), it gives out really big values which are wrong, you can find it in the photo below.

int in arduino is 16-bits.

All variables related to millis() should be unsigned long.

I think you want to print the value of millis() - temp

I also think it would make the code much more obvious if the variable temp was renamed startTimeMillis or something similar.

...R

Thanks for the feedback. It works !
I'm just wondering why my methode doesn't work though, I started my variable at 0, so I wanted to renew it in the while by adding the millis at that time.
I'm working on a school project in France, I'm naming my variables for the confort of my team members and other code readers. It's actually in French.

The value of millis() starts at 0 when the Arduino restarts and keeps counting up for about 49 days before it goes back to 0.

What you were doing is similar to adding 10 at 10am and adding another 12 at 12am (giving 22, for a silly example) whereas the time between 10am and 12am is 12 - 10 = 2 hrs.

When you run into this sort of problem with a computer program it is usually a good idea to print the "raw" data (in this case millis() ) as well as the calculated data so you can see how they relate to each other.

...R