Digital I/O Demo 3 -- Starting a digital out schedule using a digital input trigger ========================================================================================== In this demo, we set up different schedules for digital out values, which will be activated with digital in triggers. We upload a waveform to the Digital Out buffer at address ``0 + 4096*desired_digital_in_trigger``. The waveform will always be executed on the digital out determined by the waveform, but how it gets started depends on the address you write the waveform to. The value of your waveform should be determined by :math:`\sum\limits_{all~channel} 2^{d_{out}}`. Therefore, you assign 1 for output on digital out 0, you put 2 for digital out 1 and if you want to output to both Digital Out 0 and 1, you would put 1+2 = 3, up to a value of 2^16 - 1. ``doutWaveform = [ 2, 0, 0, 0, 0, 1, 1, 1];`` ``Datapixx('WriteDoutBuffer', doutWaveform, doutBufferBaseAddr + 4096*2);`` For example, this will send ``[0 0 0 0 0 1 1 1]`` on Digital Out 0 and ``[1 0 0 0 0 0 0 0]`` on Digital Out 2 whenever Digital In 2 is triggered (this corresponds to RESPONSEPixx Green button). Since the last value of the waveform gets replaced by the default value almost instantly, your device reading the Digital In signal might not be triggered by it. A possible fix is to specify to the Digital Out schedule an extra frame. In this case, we set the third argument of ``Datapixx('SetDoutSchedule', 0, 1000, 9, doutBufferBaseAddr);`` to be 9 instead of 8 to overcome that. To start this special kind of schedule, we must first set the digital in you are going to use as a trigger to the right direction. ``Datapixx('SetDinDataDirection', 0);`` sets all the digital ins to be directed towards the device (digital in can be configured as digital out, for example if you want to light up the buttons on the RESPONSEPixx). Once this is done, the schedule is started using ``Datapixx('EnableDoutButtonSchedules');`` and will run until manually stopped (or when the device is reset). .. literalinclude:: ../DatapixxToolbox/DatapixxDemos/DatapixxDoutButtonScheduleDemo.m :language: matlab :linenos: