0
0
Embedded Cprogramming~10 mins

Debouncing as a state machine in Embedded C - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
AIDLE
BPRESSED
CRELEASED
DWAIT
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.
2fill in blank
medium

Complete 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'
A0
B1
CHIGH
DTRUE
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0 for pressed state.
Confusing HIGH and LOW logic levels.
3fill in blank
hard

Fix the error in the debounce timer reset code.

Embedded C
debounce_timer = [1];
Drag options to blanks, or click blank then click option'
A0
BDEBOUNCE_DELAY
C1
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Setting timer to 0 resets it immediately.
Using negative values causes errors.
4fill in blank
hard

Fill 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'
ABUTTON_IDLE
BBUTTON_PRESSED
CBUTTON_RELEASED
DBUTTON_WAIT
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong current state in condition.
Setting state to RELEASED instead of PRESSED.
5fill in blank
hard

Fill 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'
A0
BDEBOUNCE_DELAY
CBUTTON_WAIT
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 instead of 0 for pressed input.
Setting wrong state after starting timer.