-
Notifications
You must be signed in to change notification settings - Fork 891
/
clocksAndTimers.py
49 lines (38 loc) · 1.26 KB
/
clocksAndTimers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Demo for clocks and count-down timers
"""
from __future__ import division
from __future__ import print_function
from psychopy import core
core.wait(0.5) # give the system time to settle
# create a clock
clock = core.Clock()
clock.reset() # whenever you like
# to create a timer you can 'add' time to the zero point
# and wait to get back to zero
timer = core.Clock()
timer.add(3)
# there's also a countdown timer (just a flip of the clock)
countDown = core.CountdownTimer()
countDown.add(3)
another = core.Clock()
print("down up clock")
while countDown.getTime() > 0:
msg = "%.4f %.4f %.4f"
print(msg % (countDown.getTime(), timer.getTime(), clock.getTime()))
core.wait(0.2) # this combined + print will allow a gradual timing 'slip'
# use the timer, rather than wait(), to prevent the slip
print("\ndown clock")
timer.reset()
timer.add(0.2)
countDown.add(3)
while countDown.getTime() > 0:
print("%.4f %.4f" %(countDown.getTime(), clock.getTime()))
while timer.getTime() < 0: # includes the time taken to print
pass
timer.add(0.2)
print("The last run should have been precise sub-millisecond")
core.quit()
# The contents of this file are in the public domain.