Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define the initial state of the debounce state machine.
Embedded C
typedef enum { BUTTON_[1], BUTTON_PRESSED, BUTTON_RELEASED } ButtonState; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a state that implies the button is already pressed.
Using a state name not defined in the enum.
✗ Incorrect
The initial state is usually IDLE, meaning no button press detected yet.
2fill in blank
mediumComplete the code to check if the button input is pressed (active low).
Embedded C
if (button_input == [1]) {
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0 for pressed state.
Confusing HIGH and LOW logic levels.
✗ Incorrect
For active low buttons, pressed means the input reads 0.
3fill in blank
hardFix the error in the debounce timer reset code.
Embedded C
debounce_timer = [1]; Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting timer to 0 resets it immediately.
Using negative values causes errors.
✗ Incorrect
The timer should be set to the debounce delay constant to start counting down.
4fill in blank
hardFill both blanks to update the state machine when the button is pressed and debounce timer expires.
Embedded C
if (debounce_timer == 0 && button_state == [1]) { button_state = [2]; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong current state in condition.
Setting state to RELEASED instead of PRESSED.
✗ Incorrect
When timer expires and state is IDLE, update state to PRESSED.
5fill in blank
hardFill all three blanks to implement the debounce state machine update logic.
Embedded C
switch (button_state) {
case BUTTON_IDLE:
if (button_input == [1]) {
debounce_timer = [2];
button_state = [3];
}
break;
// other states omitted for brevity
} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0 for pressed input.
Setting wrong state after starting timer.
✗ Incorrect
When button input is 0 (pressed), start debounce timer and move to WAIT state.