23 Write a function that sets an LED to the given state (on or off) and then pauses

In MATLAB edit the function named setLEDandWait that sets an LED to a specified state (on or off) and then pauses for a specified amount of time. The function should satisfy all of the following requirements:

  1. it should return no value
  2. it should be named setLEDandWait
  3. it should have three input variables called index, state, and seconds. index is the index of the digital output that the LED is connected to. state is the state of the LED; if state is equal to 1 (or true) then the LED should be turned on and if state is equal to 0 (or false) then the LED should be turned off. seconds is the number of seconds to pause.
  4. it should cause Steps 5-6 to occur in sequence and then end
  5. it should set the state of the LED at digital output index to state
  6. it should pause for seconds seconds

Test your function in the MATLAB Command Window by trying to turn LEDs 0 through 3 on and off:

% turn LED 0 on and pause for 2 seconds
setLEDandWait(0, 1, 2)

% turn LED 0 off and pause for 2 seconds
setLEDandWait(0, 0, 2)

% turn LED 1 on and pause for 2 seconds
setLEDandWait(1, 1, 2)

% turn LED 1 off and pause for 2 seconds
setLEDandWait(1, 0, 2)

% turn LED 2 on and pause for 2 seconds
setLEDandWait(2, 1, 2)

% turn LED 2 off and pause for 2 seconds
setLEDandWait(2, 0, 2)

% turn LED 3 on and pause for 2 seconds
setLEDandWait(3, 1, 2)

% turn LED 3 off and pause for 2 seconds
setLEDandWait(3, 0, 2)