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:
- it should return no value
- it should be named
setLEDandWait - it should have three input variables called
index,state, andseconds.indexis the index of the digital output that the LED is connected to.stateis the state of the LED; if state is equal to1(or true) then the LED should be turned on and if state is equal to0(or false) then the LED should be turned off.secondsis the number of seconds to pause. - it should cause Steps 5-6 to occur in sequence and then end
- it should set the state of the LED at digital output
indextostate - it should pause for
secondsseconds
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)