24 Write a function that computes the next LED to control
In MATLAB edit the function named nextIndex
that computes the index of the next LED to control. The function should satisfy all of the following requirements:
- it should return a value named
next
- it should be named
nextIndex
- it should have one input variable called
curr
that is equal to the index of the LED that was most recently turned on or off - it should return
next
the index of the next LED to blink given the indexcurr
of the LED that was most recently turned on or off
For example:
nextIndex(0)
should return1
nextIndex(1)
should return2
nextIndex(2)
should return3
nextIndex(3)
should return0
nextIndex(4)
should return1
nextIndex(5)
should return2
nextIndex(6)
should return3
nextIndex(7)
should return0
- and so on
Your function should not use any if
statements or switch
statements; instead, you should simply wrap the value curr + 1
to the range 0 to 3 using mod
or rem
.
Test your function in the MATLAB Command Window to ensure that your function returns the expected values shown above.