function t = RTBox_WaitForFlash;
% This function fires up the RTBox, and waits until the light goes on.
% It then closes down the RTBox and returns the time of the light onset.
% This is only intended to be used once per experiment, at the beginning. I
% would not open and close the RTbox each time if I were reading many
% flashes.a
% Jenny Read, August 2010

%ratio = RTBox('ClockRatio'); - only necessary at start-up or if the RTbox
%loses USB power at any point.

RTBox('enable','light'); % enable light detection for trigger, also open device if needed
% Stop RTBox responsding to button-presses; I only want to know about light
RTBox('disable', {'release'  'press'} );
RTBox('clear')
fprintf('Waiting for light flash...');
t=RTBox(inf); % wait until event happens (and since I have disabled all other buttons, it must be light flash)
fprintf('Detected light flash at time %5.3f\n',t);
RTBox('close',0)