Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define the number of states.
Embedded C
enum States { STATE_IDLE, STATE_PROCESS, STATE_DONE, [1] }; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a name that does not represent the count of states.
Forgetting to add a count identifier at the end.
✗ Incorrect
The enum ends with STATE_COUNT to represent the total number of states.
2fill in blank
mediumComplete the code to declare the state transition function pointer type.
Embedded C
typedef void (*StateFunc)([1]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using int or other types instead of void.
Adding parameters when none are needed.
✗ Incorrect
The state functions take no parameters and return void.
3fill in blank
hardFix the error in the state transition table declaration.
Embedded C
StateFunc state_table[[1]] = { state_idle, state_process, state_done }; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Hardcoding the size instead of using STATE_COUNT.
Using an incorrect size causing out-of-bounds errors.
✗ Incorrect
The array size should be STATE_COUNT to match the enum count.
4fill in blank
hardFill both blanks to correctly update the current state using the transition table.
Embedded C
current_state = [1]; state_table[[2]]();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling the function with next_state instead of current_state.
Not updating current_state before calling the function.
✗ Incorrect
Assign next_state to current_state, then call the function for current_state.
5fill in blank
hardFill all three blanks to define the state transition table with correct function pointers.
Embedded C
StateFunc state_table[STATE_COUNT] = { [1], [2], [3] }; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Including a function not defined in the enum.
Mixing the order of functions.
✗ Incorrect
The table must list the functions for each state in order.