#1
|
|||
|
|||
timer question
Ok, so I feel really stupid but I can't figure this one out. I'm trying to implement a timer that tells you how much time has elapsed at certain intervals. In other words, if I'm running a 600 second (10 min) trial, I'd like to be notified when 300 seconds have passed, when 400 seconds have passed and when 500 seconds have passed (or something like that). The problem is, when I run this (there's more code above but it has nothing to do with the elapsed time):
def mytimer2(num): if num == 0: print 'Elapsed time:', viz.elapsed(),'seconds' def onkeydown(key): if key == ' ': viz.starttimer(0,(1.0/40),viz.FOREVER) viz.starttimer(1,60,1) viz.callback(viz.KEYDOWN_EVENT,onkeydown) viz.callback(viz.TIMER_EVENT,mytimer) viz.callback(viz.TIMER_EVENT,mytimer2) viz.starttimer(0,2.4) I get: Elapsed time: 0.0404154717988 seconds Elapsed time: 0.0300169434942 seconds Elapsed time: 0.0302259086001 seconds Elapsed time: 0.0502695174945 seconds Elapsed time: 0.0304756610128 seconds Elapsed time: 0.0594360456427 seconds Elapsed time: 0.0897818018771 seconds Elapsed time: 0.0305709245169 seconds Elapsed time: 0.0611904585639 seconds Elapsed time: 0.0498390158526 seconds Elapsed time: 0.0498803618896 seconds Elapsed time: 0.0499303682451 seconds Elapsed time: 0.0499004761778 seconds Elapsed time: 0.0499605396775 seconds Elapsed time: 0.0499921079355 seconds Elapsed time: 0.0499136063382 seconds Elapsed time: 0.0498828761756 seconds Elapsed time: 0.049988476189 seconds Elapsed time: 0.0497297840927 seconds Elapsed time: 0.0501510666858 seconds Elapsed time: 0.0498091237853 seconds Elapsed time: 0.0497898475924 seconds Elapsed time: 0.0499610984078 seconds Elapsed time: 0.049934838087 seconds Elapsed time: 0.0399550780895 seconds Elapsed time: 0.0258921175736 seconds Elapsed time: 0.0327119787571 seconds Elapsed time: 0.0332114835824 seconds Elapsed time: 0.0335727026759 seconds Elapsed time: 0.0540660894052 seconds Elapsed time: 0.0300367784174 seconds Elapsed time: 0.0900379796874 seconds Elapsed time: 0.0254152413226 seconds Elapsed time: 0.0536895052304 seconds Elapsed time: 0.0293087529281 seconds Elapsed time: 0.0709419772625 seconds Elapsed time: 0.0289522830416 seconds Elapsed time: 0.0506083873788 seconds Elapsed time: 0.0323689183961 seconds Elapsed time: 0.0676222816028 seconds Elapsed time: 0.0321641437669 seconds Elapsed time: 0.0475708504852 seconds Elapsed time: 0.0351245758888 seconds Elapsed time: 0.0446880818652 seconds Elapsed time: 0.0388387350906 seconds Elapsed time: 0.051005365207 seconds Elapsed time: 0.0321038009021 seconds Elapsed time: 0.0441273960797 seconds Elapsed time: 0.0390069128898 seconds Elapsed time: 0.034387890081 seconds Elapsed time: 0.0319954072375 seconds Elapsed time: 0.0559900769511 seconds Elapsed time: 0.0301099720775 seconds Elapsed time: 0.0698421168053 seconds Elapsed time: 0.0304359911665 seconds Elapsed time: 0.0512134922176 seconds Elapsed time: 0.0484530855179 seconds Elapsed time: 0.0595718170885 seconds Elapsed time: 0.0304052610038 seconds Elapsed time: 0.0342286519655 seconds Elapsed time: 0.149784120608 seconds Elapsed time: 0.0693127199127 seconds Elapsed time: 0.0901446971612 seconds Elapsed time: 0.0799568101532 seconds Elapsed time: 0.069858319982 seconds Elapsed time: 0.140486849586 seconds Elapsed time: 0.0492009459303 seconds Elapsed time: 0.0299817434897 seconds Elapsed time: 0.039783547909 seconds Elapsed time: 0.0399014399875 seconds Elapsed time: 0.0600785854068 seconds Elapsed time: 0.059874648873 seconds Elapsed time: 0.0397114717094 seconds Elapsed time: 0.0600822171533 seconds Elapsed time: 0.0391546970355 seconds Elapsed time: 0.0407870274015 seconds Elapsed time: 0.0397782399718 seconds Elapsed time: 0.0499708761868 seconds Elapsed time: 0.0298599402997 seconds Elapsed time: 0.039700855835 seconds Elapsed time: 0.0402174019324 seconds Elapsed time: 0.0398086907694 seconds Elapsed time: 0.0507089588202 seconds Elapsed time: 0.250029822226 seconds Elapsed time: 0.129951991105 seconds Elapsed time: 0.210361931475 seconds Elapsed time: 0.0701253930318 seconds Elapsed time: 0.140293528926 seconds Elapsed time: 0.0890523795622 seconds Elapsed time: 0.0709620915507 seconds Elapsed time: 0.079391933891 seconds Elapsed time: 0.140002430476 seconds Elapsed time: 0.0799908926973 seconds Elapsed time: 0.089535960576 seconds Elapsed time: 0.0325985565205 seconds Elapsed time: 0.0874242396729 seconds Elapsed time: 0.089893547923 seconds Elapsed time: 0.0597355250458 seconds Elapsed time: 0.0598123504524 seconds Elapsed time: 0.0403749638571 seconds Elapsed time: 0.0594826996169 seconds Elapsed time: 0.0401626463699 seconds Elapsed time: 0.0596958551995 seconds Elapsed time: 0.0400877765191 seconds Elapsed time: 0.0621375063032 seconds Elapsed time: 0.0377503286032 seconds Elapsed time: 0.0878555794102 seconds Elapsed time: 0.0416790402132 seconds Elapsed time: 0.0607434743801 seconds Elapsed time: 0.0548544577593 seconds Elapsed time: 0.0846071218549 seconds Elapsed time: 0.0320761437557 seconds Elapsed time: 0.0330757121366 seconds Elapsed time: 0.0339185566881 seconds Elapsed time: 0.0502295682831 seconds Elapsed time: 0.0311514452256 seconds Elapsed time: 0.0512213144408 seconds Elapsed time: 0.0322535406036 seconds Elapsed time: 0.0328541756005 seconds Elapsed time: 0.0335822010898 seconds Elapsed time: 0.03859401125 seconds Elapsed time: 0.027829514645 seconds Now, if I don't press the spacebar to start the stimulus then I'll get this: Elapsed time: 2.42326859978 seconds Elapsed time: 2.41321369057 seconds but once I press the key to start the program, I get the output above. Is there a way that I can bypass all of that output every 0.0XXXXX seconds and just get Vizard to print when X, Y, Z, etc. seconds have passed??? |
#2
|
|||
|
|||
You can only register one global callback at a time. You are registering 2 timer callbacks with the following commands:
Code:
viz.callback(viz.TIMER_EVENT,mytimer) viz.callback(viz.TIMER_EVENT,mytimer2) Code:
def timer1(): print 'timer1 elapsed',viz.elapsed() vizact.ontimer(0,timer1) def timer2(): print 'timer2 elapsed',viz.elapsed() vizact.ontimer(0.5,timer2) |
#3
|
|||
|
|||
I want to keep the original mytimer because that enables the stimulus to run when i press the spacebar. But i don't know how to incorporate the other timer--time elapsed--into the code. I tried the example you said, but it didn't work for me. Maybe i did something wrong. Also how would I do it if i wanted to use event classes.
|
#4
|
|||
|
|||
Can you be a little more specific about how it didn't work. Did it print out an error? There is an example in the documentation that shows how to use event classes. Just search for "EventClass" and it should be the first result.
|
#5
|
|||
|
|||
it didn't work because it still printed out:
Elapsed time: 0.0404154717988 seconds Elapsed time: 0.0300169434942 seconds Elapsed time: 0.0302259086001 seconds Elapsed time: 0.0502695174945 seconds Elapsed time: 0.0304756610128 seconds Elapsed time: 0.0594360456427 seconds Elapsed time: 0.0897818018771 seconds Elapsed time: 0.0305709245169 seconds Elapsed time: 0.0611904585639 seconds Elapsed time: 0.0498390158526 seconds Elapsed time: 0.0498803618896 seconds Elapsed time: 0.0499303682451 seconds Elapsed time: 0.0499004761778 seconds Elapsed time: 0.0499605396775 seconds Elapsed time: 0.0499921079355 seconds Elapsed time: 0.0499136063382 seconds Elapsed time: 0.0498828761756 seconds Elapsed time: 0.049988476189 seconds Elapsed time: 0.0497297840927 seconds Elapsed time: 0.0501510666858 seconds Elapsed time: 0.0498091237853 seconds and didn't print out what I specified. I don't know. Maybe I'm doing something wrong. |
#6
|
|||
|
|||
Nevermind I figure it out...I'm a moron
|
|
|