Question: C programming Please use the same sturcture below. Program Structure: declare ButtonState; // Global variable holding status of button unsigned long Time; // Holds time

C programming

Please use the same sturcture below.

Program Structure:

declare ButtonState; // Global variable holding status of button

unsigned long Time; // 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: // State where nothing has been happening.

if input is low,

Time = millis(); // Record time of high to low transition.

set ButtonState to Wait // Move to Wait state.

Turn on LED (Pin 13 high)

Wait: // Button has gone low and we are waiting for it to remain low for 5 milliseconds

if input is high, // 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.

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 // 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.

if( ButtonNextState( digitalRead( input ) )

Send serial message indicating button press // Indicate button has been pressed. ((((Dont forget please to write a code that when ever the the buttom clicked will disaible meassge saying buttom clicked )))

end of if

....

thank you in advance

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!