# Timer after button pressed

**URL:** <https://discourse.processing.org/t/timer-after-button-pressed/27209>\
**Category:** Coding Questions\
**Created:** [January 19, 2021, 9:17pm UTC](https://discourse.processing.org/t/timer-after-button-pressed/27209 "2021-01-19T21:17:21Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![saaqib.m](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@saaqib.m](https://discourse.processing.org/u/saaqib.m)\
**Post date:** [January 19, 2021, 9:17pm UTC](https://discourse.processing.org/t/timer-after-button-pressed/27209/1 "2021-01-19T21:17:21Z")

</div>

> please format code with \</\> button \* [homework policy](https://discourse.processing.org/faq/#homework) \* [asking questions](https://discourse.processing.org/t/2147)

After I run a program, I want my timer to start. Currently I am using millis()/1000 just for the seconds but I want to make the timer so that it gives the minutes too. I know how to display it but i just need to know how i can make the millis update every 60 seconds so it goes back to 0. Thank you.

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [January 19, 2021, 9:24pm UTC](https://discourse.processing.org/t/timer-after-button-pressed/27209/2 "2021-01-19T21:24:38Z")

</div>

60 seconds = 6000 milliseconds so divide your milliseconds by 1000. Note you could take the modulus of millais ie if(millis%1000==0)doSomething(= but note you will have to take the starting time away or the initial time the button was pressed.

---

<div class="post-metadata">

**Author:** ![saaqib.m](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@saaqib.m](https://discourse.processing.org/u/saaqib.m)\
**Post date:** [January 19, 2021, 9:42pm UTC](https://discourse.processing.org/t/timer-after-button-pressed/27209/3 "2021-01-19T21:42:31Z")

</div>

I have this currently:

```auto
int tElapsed =0;
int tStart = 0;
tElapsed = (millis()/1000)-tStart;
if (tElapsed> millis()/1000+60) {tElapsed = tStart;};

```

im trying to set tElapsed to 0 every time millis() reaches 60 seconds

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [January 19, 2021, 9:42pm UTC](https://discourse.processing.org/t/timer-after-button-pressed/27209/4 "2021-01-19T21:42:47Z")

</div>

Here is the code I made : P

> **Code**
>
> ```auto
> void setup() {} void draw() {
> int m = millis(), sec = floor(millis()/1000) % 60, min = floor(floor(millis()/1000)/60) % 60, hr = floor(floor(floor(millis()/1000)/60)/60) % 24, d = floor(floor(floor(floor(millis()/1000)/60)/60/24)),y = floor(floor(floor(floor(millis()/1000)/60)/60/24)/365);
> println("Days:",nf(d,2),("(Y:"+y+",D:"+d%365+")"),"Hr:Min:Sec",nf(hr,2)+":"+nf(min,2)+":"+nf(sec,2));
> }
> 
> ```

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/2/250aa3524e6864240eb9dd3d7fb55c755a311f7b.png)  
Days: [total number] (Y:[years],D:[days (%365)]) Hr:Min:Sec [hrs]:[min]:[sec]

---

<div class="post-metadata">

**Author:** ![saaqib.m](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@saaqib.m](https://discourse.processing.org/u/saaqib.m)\
**Post date:** [January 19, 2021, 9:52pm UTC](https://discourse.processing.org/t/timer-after-button-pressed/27209/5 "2021-01-19T21:52:27Z")

</div>

Thank you so much!!! This is EXACTLY what I needed!

---

<div class="post-metadata">

**Author:** ![saaqib.m](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@saaqib.m](https://discourse.processing.org/u/saaqib.m)\
**Post date:** [January 19, 2021, 9:54pm UTC](https://discourse.processing.org/t/timer-after-button-pressed/27209/6 "2021-01-19T21:54:59Z")

</div>

Would you happen to know how I would be able to include the milliseconds too? Not just the full milliseconds, the second or second and third value of it? Because m/1000 gives seconds but m/100 wouldn’t give me what I want.

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [January 19, 2021, 10:05pm UTC](https://discourse.processing.org/t/timer-after-button-pressed/27209/7 "2021-01-19T22:05:42Z")

</div>

to print normal milliseconds just use `println(millis() % 1000);`

---

<div class="post-metadata">

**Author:** ![saaqib.m](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@saaqib.m](https://discourse.processing.org/u/saaqib.m)\
**Post date:** [January 19, 2021, 10:14pm UTC](https://discourse.processing.org/t/timer-after-button-pressed/27209/8 "2021-01-19T22:14:02Z")

</div>

If I may explain further. For example: millis() = 1234.  
The 1 is the seconds, the 2 is how fast the 1 changes, the 3 is how fast the 2 changes etc correct/? I would just like to obtain the value of 2.

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [January 19, 2021, 10:18pm UTC](https://discourse.processing.org/t/timer-after-button-pressed/27209/9 "2021-01-19T22:18:07Z")

</div>

```auto
  //12345/100 = 123  
  //123 - (123/10)*10 = 3  
  
  println( 12345/(10*10) - (12345/(10*10)/ 10)*10 );

```

I took this basic idea and wrote a function to extract any digit.

Give it a try!

`:)`

---

<div class="post-metadata">

**Author:** ![saaqib.m](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@saaqib.m](https://discourse.processing.org/u/saaqib.m)\
**Post date:** [January 19, 2021, 10:24pm UTC](https://discourse.processing.org/t/timer-after-button-pressed/27209/10 "2021-01-19T22:24:53Z")

</div>

Thank you very much! It worked perfectly :))
