ELFORUM - Forumul electronistilor

# resetare millies()

## Recommended Posts

Salutare,

Incerc sa resetez functia millies la fiecare 60 de secunde, mai exact variabila timer_sec

```unsigned long timer_min;
unsigned long timer_sec;
String min_sec;

void setup(){
Serial.begin(9600);
}
void loop(){
timer_min = millis()/1000/60;
timer_sec = millis()/1000;

if(timer_sec == 60){
timer_sec = 0;
}

min_sec = String(timer_min) + "min : " + String(timer_sec) + "sec";

Serial.println(min_sec);
delay(1000);
}```

am incercat cu acel if, insa dupa ce trece de el variabila timer_sec isi continua numerotarea.

Cum as putea ca in variabila min_sec, variabila timer_sec sa fie resetata la fiecare 60 secunde?

Multumesc!

• Replies 4
• Created

#### Popular Days

Salut,

Incearca asa:

`timer_min = (millis()/1000)%60;`

Iar functia millis() nu ai cum s-o resetezi. Ete ce zice la docoment:

Returns the number of milliseconds since the Arduino board began running the current program. This number will overflow (go back to zero), after approximately 50 days.

Edited by cirip

Colegul de mai sus a raspuns corect dar a gresit numele variabilei, vorbim de timer_sec.

Si atunci loop devine:

```unsigned long timer_min;
unsigned long timer_sec;
String min_sec;

void setup(){
Serial.begin(9600);
}

void loop(){
timer_min = millis()/1000/60;
timer_sec = (millis()/1000)%60;

min_sec = String(timer_min) + "min : " + String(timer_sec) + "sec";

Serial.println(min_sec);
delay(1000);
}```

3 hours ago, dany_cta said:

a gresit numele variabilei,

Corect! Desi, cred ca si minutele si secundele tre' facute modulo 60 pentru cand o pune si orele. Dar mai bine sa-l lasam sa citeasca un pic ce e cu % asta ...

Multumesc mult de ajutor!

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×

×
×
• Create New...