Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

// Debounce FSM // This FSM simply debounces the button status, it acts as a fil

ID: 3754719 • Letter: #

Question

// Debounce FSM
// This FSM simply debounces the button status, it acts as a filter that removes the undesired bounces
// This FSM has two inputs the raw button status (rawButtonStatus). The input struct holds info on which port/pin to check.
// The other input is the status of the timer. The input struct hold info about which timer to check.

// The FSM also has two outputs. One is the debounced button status (debouncedButtonStatus), which is also the output of this function
// The other output is a boolean that decides whether to start the timer. This output of the FSM is internal to the function.

char Debounce(button_t *button) {

    // The first input of the FSM
    char rawButtonStatus = GPIO_getInputPinValue(button->Port, button->Pin);

    // The second input of the FSM
    bool timerExpired = (Timer32_getValue(button->timer) == 0);

    // outputs of the FSM
    bool debouncedButtonStatus;
    bool startTimer = false;

    // The button struct holds info on the debouncing state of the button
    // e.g. it knows if the button is in transition or not
    switch (button->Debounce_state)
    {
    case Stable_P:
        // The output of both arcs is the same so we can put this statement outside the transition arcs
        debouncedButtonStatus = PRESSED;
        if (rawButtonStatus != PRESSED)
        {
            // Change state
            button->Debounce_state = Tran_PtoR;

            // Update outputs, if different from default
            startTimer = true;

         }
        break;
        // implement the rest of states and their transition arcs HERE

        }

    if (startTimer)
    {
        Timer32_setCount(button->timer, ONE_HUNDRED_MS_COUNT);
        Timer32_startTimer(button->timer, true);

    }
    return debouncedButtonStatus;
}

Explanation / Answer

import java.util.Timer; import java.util.TimerTask; /** * Simple demo that uses java.util.Timer to schedule a task * to execute once 5 seconds have passed. */ public class Reminder { Timer timer; public Reminder(int seconds) { timer = new Timer(); timer.schedule(new RemindTask(), seconds*1000); } class RemindTask extends TimerTask { public void run() { System.out.println("Time's up!"); timer.cancel(); //Terminate the timer thread } } public static void main(String args[]) { new Reminder(5); System.out.println("Task scheduled."); } }