# How to keep stimulus on screen for certain length of time

**URL:** <https://psychtoolbox.discourse.group/t/how-to-keep-stimulus-on-screen-for-certain-length-of-time/3360>\
**Category:** Programming Help\
**Created:** [August 22, 2020, 3:06pm UTC](https://psychtoolbox.discourse.group/t/how-to-keep-stimulus-on-screen-for-certain-length-of-time/3360 "2020-08-22T15:06:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cai](https://avatars.discourse-cdn.com/v4/letter/c/6f9a4e/32.png) [@Cai](https://psychtoolbox.discourse.group/u/Cai)\
**Post date:** [August 22, 2020, 3:06pm UTC](https://psychtoolbox.discourse.group/t/how-to-keep-stimulus-on-screen-for-certain-length-of-time/3360/1 "2020-08-22T15:06:58Z")

</div>

I am using Psychtoolbox on MATLAB R2020a on Mac OS. I am trying to get the fixation cross to stay on the screen for 10 seconds before displaying the next stimulus. I have tried WaitSec() but this did not work.

```
% Experimental instructions
line1 = 'Choose the sequence with the highest mean';
line2 = '\n Press any key when you are ready to begin';

% Draw all the text in one go
Screen('TextSize', window, 40);
Screen('TextFont', window, 'Ariel');
DrawFormattedText(window, [line1 line2],...
    'center', 'center', white);
Screen('Flip', window);
KbStrokeWait;

% Fixation cross
Screen('DrawLines', window, allCoords,lineWidthPix, white, [xCenter yCenter], 2);

% trial 1
DrawFormattedText(window, sprintf(seq1), rightX, rightY, [0 1 0]);
DrawFormattedText(window, sprintf(seq2), leftX, leftY, [1 0 1]);
DrawFormattedText(window, sprintf(seq3), upX, upY, [1 1 0]);
```

---

<div class="post-metadata">

**Author:** ![dcnieho](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@dcnieho](https://psychtoolbox.discourse.group/u/dcnieho)\
**Post date:** [August 23, 2020, 6:14am UTC](https://psychtoolbox.discourse.group/t/how-to-keep-stimulus-on-screen-for-certain-length-of-time/3360/2 "2020-08-23T06:14:46Z")

</div>

Use the when argument to Screen(‘Flip’) for precisely timing when things are shown, such as the next thing after your fixation cross.

---

<div class="post-metadata">

**Author:** ![Cai](https://avatars.discourse-cdn.com/v4/letter/c/6f9a4e/32.png) [@Cai](https://psychtoolbox.discourse.group/u/Cai)\
**Post date:** [August 23, 2020, 11:13am UTC](https://psychtoolbox.discourse.group/t/how-to-keep-stimulus-on-screen-for-certain-length-of-time/3360/3 "2020-08-23T11:13:22Z")

</div>

Thanks. Could you please explain how to construct the when argument? I tried:

`when(Screen('DrawLines', window, allCoords,lineWidthPix, white, [xCenter yCenter], 2), WaitSecs(10));`

But that did not work.

---

<div class="post-metadata">

**Author:** ![dcnieho](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@dcnieho](https://psychtoolbox.discourse.group/u/dcnieho)\
**Post date:** [August 23, 2020, 8:17pm UTC](https://psychtoolbox.discourse.group/t/how-to-keep-stimulus-on-screen-for-certain-length-of-time/3360/4 "2020-08-23T20:17:40Z")

</div>

Read “Screen Flip?”, Thats how you get help for the PTB functions. One of the inputs is when. See some of Peter Scarfe’s ptb demos as a start, they’ll tell you about basic use and how to do proper timing
