Digital I/O Demo 4 -- Creating a digital out TTL trigger with synchronization ===================================================================================== In this demo, we create a trigger that will be sent every video frame a set amount of times. For this demo, the schedule does not run at a rate specified in Hz, but every frame. The Vertical Sync (Vsync) is what starts/triggers the schedule. We define a pulse, and write it in the Digital Out buffer ``Datapixx('WriteDoutBuffer', doutWave, bufferAddress);``. We also decide to send 16 triggers per frame and to let the schedule run for 100 frames. ``Datapixx('SetDoutSchedule', 0, [samplesPerFrame, 2], samplesPerTrial, bufferAddress, samplesPerTrigger);`` is called. If the second argument, ``[samplesPerFrame, 2]``, had not been followed by an argument, ``samplesPerFrame`` would have been expressed in Hz. For that argument, nothing or 1 is Hz, 2 is to define the sample rate per frame and 3 would be the period with double precision (:math:`Period = \frac{1}{Frequency}`). To start the schedule on a Vsync, we call ``Datapixx('RegWrVideoSync');`` the schedule will then start on the following ``Screen('Flip', win);``. .. literalinclude:: ../DatapixxToolbox/DatapixxDemos/DatapixxDoutTriggerDemo.m :language: matlab :emphasize-lines: 31, 39, 44-45 :linenos: