try
    HideCursor;
    [w, rect] = Screen('Openwindow',0);
    grey= 128;
    black =0;
    adjustable = 90;
    cx = rect(3)/2;
    cy = rect(4)/2;
    size=60;
    displacement = cx/2;
    coordLeft =[cx-displacement-size cy-size cx-displacement+size cy+size];
    coordRight=[cx+displacement-size cy-size cx+displacement+size cy+size];
    coordBlack = [0 0 cx rect(4)];
    Screen('TextSize', w,12) ;
    Instructions = 'Press the Up and Down arrow keys to adjust the' +
    'of the square to your right to match the color of the other.';
    Instructions2 = 'Press Esc when you are satisfied with your match.';
    while 1
        Screen('FillRect',w, black,coordBlack);
        Screen('DrawText',w, Instructions, 10, 20,grey);
        Screen('DrawText',w, Instructions2, 10,40,grey);
        Screen('FillRect',w, grey,coordLeft);
        Screen('FillRect',w, adjustable,coordRight);
        Screen('Flip', w);
        [ keyIsDown, s, keyCode ] = KbCheck;
        if keyCode(38)
            adjustable=adjustable+1;
        elseif keyCode(40)
            adjustable=adjustable-1;
        elseif keyCode(27)
            break;
        end
    end
    Screen('DrawText',w, sprintf('Your final RGB was %d, press any key to exit.', adjustable),10,60);
    Screen('Flip', w);
    while kbcheck end
    KbWait;
    ShowCursor;
    Screen('Close',w)
catch
    screen('Close',w)
    rethrow(lasterror)
end