Question: Write following code section to C Program Structure: declare ButtonState; // Global variable holding status of button unsigned long ButtonTime; 1/ Holds time to debounce
Write following code section to C

Program Structure: declare ButtonState; // Global variable holding status of button unsigned long ButtonTime; 1/ Holds time to debounce Switch int ButtonNextState( input) // function that is to be called in loop to service the switch switch based on ButtonState Idle: /7 State where nothing has been happening. if input is low, ButtonTime-millis I/ Record time of high to low transition set ButtonState to Wait // Move to Wait state. Turn on LED // Pin 13 high used for debugging Wait: /7 Button has gone low and we are waiting for it to remain low for 5 milliseconds if input is high, 1/ If button has gone high, set ButtonState to Idle // Reset back to Idle. else if (millis () -time 5 // if 5 milliseconds has passed set ButtonState to Low // Move to low state. Turn off LED // Pin 13 low also used for debugging). return 1 // indicating that button has been pressed. Low: // Button is low and has been so for 5 milliseconds if input is high // Once button released. set ButtonState to Idle: end of switch return 0 /1 By default return 0 indicating nothing is happening SetUp: // Function run at the start of the program. Set pin as input. // Check Schematic in Lab 4 for pin number. Set ButtonState to Idle. // Initialize state Loop: // Function continuously called // Check status of button f( ButtonNextState ( digitalRead( input ) ) // switch is connected to pin 4. end of if Send serial message indicating button press / Indicate button has been pressed. Lab Assignment: Prelab: Write the program described in the program section. You are required to use the function call approach described above. You will need to read the button in later labs
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
