21 Control digital output 0 using MATLAB

Read the help documentation for the two functions setDigitalOutputOn and setDigitalOutputOff.

help setDigitalOutputOn
help setDigitalOutputOff

21.1 Turn the LED on

Edit the script onOff.m so that it calls the function setDigitalOutputOn to turn digital output 0 on. Save the script and run it; the LED should turn on.

Notice that the LED does not turn off when the script finishes running. To turn the LED off we have to programmatically turn it off.

21.2 Turn the LED off

In the script onOff.m on a line after you turn the LED on, call the function setDigitalOutputOff to turn digital output 0 off. Save the script and run it; the LED should turn off.

21.3 Run the script again

If you run the script again, you should see the LED briefly turn on before turning off. To control the amount of time that the LED stays on, we need to insert a pause between turning the LED on and turning it off.

21.4 Adding a pause between turning the LED on and turning the LED off

The function pause can be used to pause MATLAB for a specified number of seconds. Read the help documentation for pause:

help pause

In the script, insert two calls to pause. The first call to pause should occur after you turn the LED on. The second call to pause should occur after you turn the LED off.

Save the script and run it to confirm that the LED turns on for 1 second before turning off.

21.5 Using a different function to turn the LED on and off

The function setDigitalOutput can be used to turn a digital output either on or off. Read the help documentation for the function:

help setDigitalOutput

To the end of the script onOff.m, repeat the turning on and off of the LED with a 1 second pause in between, this time using setDigitalOutput to turn digital output 0 on and off. Save the script and run it to confirm that the LED turns on for 1 second, off for 1 second, on for 1 second, and off.