Jump to content
ELFORUM - Forumul electronistilor

resetare millies()


Guest sea

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!

Link to comment

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
Link to comment

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);
}

 

Link to comment

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.

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

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




×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.Terms of Use si Guidelines