# Start, pause, and restart timer

**URL:** <https://discourse.psychopy.org/t/start-pause-and-restart-timer/3571>\
**Category:** Coding\
**Created:** [December 7, 2017, 2:02am UTC](https://discourse.psychopy.org/t/start-pause-and-restart-timer/3571 "2017-12-07T02:02:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Felipe\_Corchs](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/felipe_corchs/32/2059_2.png) [@Felipe\_Corchs](https://discourse.psychopy.org/u/Felipe_Corchs)\
**Post date:** [December 7, 2017, 2:02am UTC](https://discourse.psychopy.org/t/start-pause-and-restart-timer/3571/1 "2017-12-07T02:02:59Z")

</div>

Dear all,

I’m programming and experiment in which the participant can move a circle through a 20 x 10 grid and I’d need to create a timer or clock that counts the total amount of time the participant left the circle in a given position. E.g., While the circle is at the A position the timer is counting, if it leaves A1 the timer is paused and when it is back to A1 the timer restarts and so on, so I’d have the total amount of time spent at A1 during that trial.

Is that a code or resource in psychopy I could use to do that?

Best regards,

Felipe

---

<div class="post-metadata">

**Author:** ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)\
**Post date:** [December 7, 2017, 2:20am UTC](https://discourse.psychopy.org/t/start-pause-and-restart-timer/3571/2 "2017-12-07T02:20:02Z")

</div>

You can reset a `Clock` or add to its start value, but once created, they are always ticking. So you need to store snapshots of time values in a variable and add to them as required. e.g. something like this:

- initialise some `total_time` variable to `0`
- Loop:
  - reset a `Clock` when entering `A1`
  - `getTime()` from that clock when leaving `A1` and add the result to `total_time`

---

<div class="post-metadata">

**Author:** ![Felipe\_Corchs](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/felipe_corchs/32/2059_2.png) [@Felipe\_Corchs](https://discourse.psychopy.org/u/Felipe_Corchs)\
**Post date:** [December 7, 2017, 3:16am UTC](https://discourse.psychopy.org/t/start-pause-and-restart-timer/3571/3 "2017-12-07T03:16:20Z")

</div>

Thanks so much, Michael.  
Best

Felipe
