Question: Exercise 1 0 . 3 TASK: Write a switch - case statement below that implements the state machine in state _ machine _ tut 1

Exercise 10.3
TASK: Write a switch-case statement below that implements the
state machine in "state_machine_tut10.png".
The switch statement should test the value of the variable
declared in Ex 10.1 and a case should be defined for every
state in the state machine (every enumerator in the enum you
declared in Ex 10.0).
Use the "pb_falling_edge" variable from Ex 10.2 to trigger the
appropriate transitions between states.
Refer to lecture video 04- State Machine Implementation
from Week 10
switch-case statement
A switch-case statement is an alterative to using a large number of if-then-else
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 STATE0, STATE1...)
Check your state machine is complete; for every transition out of a state, there
should be exactly one branch of an in-then-else 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.
 Exercise 10.3 TASK: Write a switch-case statement below that implements the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!