How to reset function second() when I start my program?

edited October 2015 in How To...

I do have 2 questions about this second() function. First, I have a program that runs for some seconds, than stops. When i try to run it again, the function second() is still keeping its value. The second question is how do i print seconds only one time. So my console will look like that 1 2 3 4 5.. etc.?

Tagged:

Answers

  • Answer ✓
  • That is grate. So i can change from milis to seconds dividing it by 1000, so the first question is answered, but what about the second one? I still have no ideea how can I print only once, 1, than 2, than 3.. Btw, thanks a lot for millis() function.

  • _vk_vk
    Answer ✓

    The good and old timer example:

    PFont font;
    String time = "000";
    int initialTime;
    int interval = 1000;//one second
    color bg = color (255);
    
    
    
    void setup()
    {
      size(300, 300);
      font = createFont("Arial", 30);
      background(255);
      fill(0);
      initialTime = millis();
        frameRate(30);// changed framerate to exemplify
    
    }
    
    void draw()
    {
      background(bg);
      if (millis() - initialTime > interval)
      {
        time = nf(int(millis()/1000), 3);
        initialTime = millis();
       bg = color (random(255), random(100), random(255));
      }
    
      text(time, width/2, height/2);
    
    
    }
    

    That's a basic one...

  • edited October 2015

    It might be basic, but I am still new at this program. Thank you a lot for your offered time. It will help me a lot in future.

Sign In or Register to comment.