Hello,
As I am a psychology PhD student with no computer science background, I apologize in advance if my questions are too basic.
Currently my experiment setting includes one projector (60Hz refresh) and four speakers connected to a USB external sound card. And I'd like to add 4 LEDs using an Arduino Uno. My main computer is MacBook Pro 15inch early 2011 model with OSX 10.9.4 and MATLAB R2012b installed.
I installed adioes.pde on my Arduino Uno R3, and wrote the following MATLAB program (see below) to test the execution time delay for each LED switch on/off. The delays are fluctuating between around 2ms and over 7ms.
My question is:
Is there any way to minimize the delay as little as 1ms or even less?
My experiment measures participants' reaction times in milliseconds, and for the obvious reason I'd like to keep the system delay as little as possible. I'd appreciate if you could give me any comments or advice regarding how to write a better program.
Thank you very much for your time.
function arduinoTest3
a = arduino('/dev/tty.usbmodemfd121');
TL = 8; % top left
TR = 10; % top right
BL = 9; % bottom left
BR = 11; % bottom right
a.pinMode(8,'output');
a.pinMode(9,'output');
a.pinMode(10,'output');
a.pinMode(11,'output');
WaitSecs(1);
t = GetSecs;
digitalWrite(a, TL, 1);
TopLeft = (GetSecs - t)*1000 % delay to execute the top left LED on/off
WaitSecs(.05);
digitalWrite(a, TL, 0);
WaitSecs(1);
t = GetSecs;
digitalWrite(a, TR, 1);
TopRight = (GetSecs - t)*1000 % delay to execute the top right LED on/off
WaitSecs(.05);
digitalWrite(a, TR, 0);
WaitSecs(1);
t = GetSecs;
digitalWrite(a, BL, 1);
BottomLeft = (GetSecs - t)*1000 % delay to execute the bottom left LED on/off
WaitSecs(.05);
digitalWrite(a, BL, 0);
WaitSecs(1);
t = GetSecs;
digitalWrite(a, BR, 1);
BottomRight = (GetSecs - t)*1000 % delay to execute the bottom right LED on/off
WaitSecs(.05);
digitalWrite(a, BR, 0);
WaitSecs(1);
delete(a);
end