Complete the code to define the initial state of the debounce state machine.
typedef enum { BUTTON_[1], BUTTON_PRESSED, BUTTON_RELEASED } ButtonState;The initial state is usually IDLE, meaning no button press detected yet.
Complete the code to check if the button input is pressed (active low).
if (button_input == [1]) {
For active low buttons, pressed means the input reads 0.
Fix the error in the debounce timer reset code.
debounce_timer = [1];The timer should be set to the debounce delay constant to start counting down.
Fill both blanks to update the state machine when the button is pressed and debounce timer expires.
if (debounce_timer == 0 && button_state == [1]) { button_state = [2]; }
When timer expires and state is IDLE, update state to PRESSED.
Fill all three blanks to implement the debounce state machine update logic.
switch (button_state) {
case BUTTON_IDLE:
if (button_input == [1]) {
debounce_timer = [2];
button_state = [3];
}
break;
// other states omitted for brevity
}When button input is 0 (pressed), start debounce timer and move to WAIT state.
