# control the cursor by joystick with pyschtoolbox and daq. Delay in refresh rate?

**URL:** <https://psychtoolbox.discourse.group/t/control-the-cursor-by-joystick-with-pyschtoolbox-and-daq-delay-in-refresh-rate/395>\
**Category:** Uncategorized\
**Created:** [November 20, 2012, 4:03am UTC](https://psychtoolbox.discourse.group/t/control-the-cursor-by-joystick-with-pyschtoolbox-and-daq-delay-in-refresh-rate/395 "2012-11-20T04:03:42Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nhatnguyen92](https://avatars.discourse-cdn.com/v4/letter/n/cab0a1/32.png) [@nhatnguyen92](https://psychtoolbox.discourse.group/u/nhatnguyen92)\
**Post date:** [November 20, 2012, 4:03am UTC](https://psychtoolbox.discourse.group/t/control-the-cursor-by-joystick-with-pyschtoolbox-and-daq-delay-in-refresh-rate/395/1 "2012-11-20T04:03:42Z")

</div>

I am writing a matlab script to control the display of cursor using the joystick. The joystick is interfaced with PC via NI USB card.  
  
Everything seems to be fine, but there are a 15ms delay in the refresh rate of Psychtoolbox (thus makes the cursor all the screen seems to vibrate a little). Is the method of collecting data below correct?  
  
Here is the skecth of my code:  
  
Initalize the daq and position of the cursor on the screen.  
  
ai = analoginput(adaptor,id);  
addchannel(ai,chanID);  
addchannel(ai,chanID2);  
set(ai, 'SampleRate', sampleRate);  
set(ai, 'SamplesPerTrigger', 100);  
  
  
while(not yet period of the experiment)  
{   
  
 start(ai);//collect data from daq,  
 Change = (getdata(ai, 1)-initialPosX) \* speed;  
 x\_Change = Change(2)\* -1;   
 y\_Change = Change(1)\*-1;  
 stop(ai);  
 % UPDATE DATA  
 dataX = round(80 \* xChange);  
 dataY = round(50 \* yChange);  
 //draw to screen  
  
}  
  
Thanks for your help!
