Question: Exercise 1 0 . 3 TASK: Write a switch - case statement below that implements the state machine in state _ machine _ tut 1
Exercise
TASK: Write a switchcase statement below that implements the
state machine in "statemachinetutpng
The switch statement should test the value of the variable
declared in Ex and a case should be defined for every
state in the state machine every enumerator in the enum you
declared in Ex
Use the pbfallingedge" variable from Ex to trigger the
appropriate transitions between states.
Refer to lecture video State Machine Implementation
from Week
switchcase statement
A switchcase statement is an alterative to using a large number of ifthenelse
statements when we want to perform different operations depending on the
value of some variable or expression. It has the syntax:
The break and default keywords are optional
break causes the switch statement to terminate.
If break is not included after a case, execution
will fall through to the next case.
If expression does not match any case, the
statements following default will be executed.
State machines: best practice
Plan your state machine before you start writing any code; draw a diagram.
Always use meaningful names for your states not STATE STATE
Check your state machine is complete; for every transition out of a state, there
should be exactly one branch of an inthenelse statement implemented in the
corresponding case.
Make sure the default case is handled; even if it should not be possible for your
state variable to take on an invalid value under normal operation.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
