Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

arduino Program Structure: Create a separate file named ButtonDebounce.h and in it write the following code. declaze Buttonstate declare Buttontine Global vaziable holding status of

arduino image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Program Structure: Create a separate file named ButtonDebounce.h and in it write the following code. declaze Buttonstate declare Buttontine Global vaziable holding status of button Should use enum to set states as ButtonIdle, Buttonalt, Buttonigh /7 unsigned long to hold tine to debounce Switch int ButtonInitialize ( // function to set up systen to read button presses set pin 4 to be an input set ButtonState to Idle State // pinMode (4, INPUT end of ButtonInitialize int ButtonNextState ( input Idle: // function that is to be called in loop to service the switch switch based on ButtonState State where nothing has been happening if input is low, Buttontime milliao /Record time of high to low transition set ButtonState to Wait // Move to Wait state Turn on LED Pin 13 high (used for debugging Nait: / Button has gone low and we are waiting for it to remain low for 5 mi11iseconds if input is high 7 f button has gone high, / Reset back to Idle set Buttonstate to Idle else if (mi11iao-time>5 st 5 mi11iseconds has passed set Buttonstate to Low Turn off LED return 1 / Move to low state Pin 13 low alsoused for debugging indicating that button has been pressed Low: 1/ Button is low and has been so for 5 mi11iseconds if input is high Once button released set ButtonState to Idle: / Go back to Idle state return 2 / Indicate that the button has been released. end of switch return // By default return 0 indicating nothing is happening. // End of Button Next state This ends the file ButtonDebounce h In the Arduino environment, do the following include "But tonDebounce.h" SetUp: / Function run at the start of the program ButtonInitialize /7 Code to set up pin and state machine 1 for monitoring push button Set up Serial for 9600 baud rate Loop: 1/ Function continuously called // Check status of button switch ButtonNextstate digitalRead4) // switch is connected to pin Send serial message indicating button press 7 Indicate button has been pressed. Send serial message indicating button released // Indicate button released case 2: end of switch Lab Assignment: Prelab: Write the program described in the program section. You are required to create the header file, with the function calls described above. You will need to read the button in later labs. Lab 5: 1) Download and demonstrate the program in the prelab. Your demonstrations should be done suclh that you verify that the messages are only sent once when the button is pressed and released. 2) Using the Analog Discovery 2, capture the timing of the debounce operation that will show on the LED (Pin 13) Include a screen capture that shows the time that pin 13 is high. The time base on the Analog Discovery should be set such that the pulse on pin 13, occupies about % of display Program Structure: Create a separate file named ButtonDebounce.h and in it write the following code. 2 of 3 declare ButtonStates Global variable holding status of button Should use enum to set states as 7 Buttonidle, ButtonMait, ButtonHigh declare ButtonTine unsigned long to hold time to debounce Switch int Buttoninitialize O /I funct i on to set up system to read button presses set pin 4 to be an input set ButtonState to Idle State pinHode (4, INPUT // end of Buttoninitialize int ButtonNextState( input Idle: tunction that is to be called in loop to service the awitch awitch based on ButtonState State where nothing has been happening. if input is low, ButtonTine-millis(); // Record tine of high to low transition. set ButtonState to Wait /7 Hove to Wait state Turn on LED Pin 13 high used for debugging Wait: // Button has gone low and ve are waiting for Lt to remain low for 5 mi11econds t input ia high lse &E (milloo-time>5r s mLseconds has passed t button has gone high Reset back to Idle set Buttonstate to Idle set ButtonState to Lou Turn off LED return 1 Move to low state Pin 13 low alsoused for debugging / indicating that button has been pressed Once button released Indicate that the button has been released Low: / Button is low and has been so for 5 mi111 seconds t input is high set Buttonstate to Idle:Goback to Idle state return 2 end of switch return 0 1/ By default return 0 Indicating nothing is happening End of Button Next state Lab 5: 1) Download and demonstrate the program in the prelab. Your demonstrations should be done such that you verify that the messages are only sent once when the button is pressed and released. 2) Using the Analog Discovery 2, capture the timing of the debounce operation that will show on the LED (Pin 13). Include a screen capture that shows the time that pin 13 is high. The time base on the Analog Discovery should be set such that the pulse on pin 13, occupies abou1% of display. ECE 241 Lab 5 Spring 2019 Points: 20 Question: What was the time you observed on pin 13, and what is the relative error between it and the 5 milliseconds it was intended to be? RelError5 S where Ar is measured in milliseconds Program Structure: Create a separate file named ButtonDebounce.h and in it write the following code. declaze Buttonstate declare Buttontine Global vaziable holding status of button Should use enum to set states as ButtonIdle, Buttonalt, Buttonigh /7 unsigned long to hold tine to debounce Switch int ButtonInitialize ( // function to set up systen to read button presses set pin 4 to be an input set ButtonState to Idle State // pinMode (4, INPUT end of ButtonInitialize int ButtonNextState ( input Idle: // function that is to be called in loop to service the switch switch based on ButtonState State where nothing has been happening if input is low, Buttontime milliao /Record time of high to low transition set ButtonState to Wait // Move to Wait state Turn on LED Pin 13 high (used for debugging Nait: / Button has gone low and we are waiting for it to remain low for 5 mi11iseconds if input is high 7 f button has gone high, / Reset back to Idle set Buttonstate to Idle else if (mi11iao-time>5 st 5 mi11iseconds has passed set Buttonstate to Low Turn off LED return 1 / Move to low state Pin 13 low alsoused for debugging indicating that button has been pressed Low: 1/ Button is low and has been so for 5 mi11iseconds if input is high Once button released set ButtonState to Idle: / Go back to Idle state return 2 / Indicate that the button has been released. end of switch return // By default return 0 indicating nothing is happening. // End of Button Next state This ends the file ButtonDebounce h In the Arduino environment, do the following include "But tonDebounce.h" SetUp: / Function run at the start of the program ButtonInitialize /7 Code to set up pin and state machine 1 for monitoring push button Set up Serial for 9600 baud rate Loop: 1/ Function continuously called // Check status of button switch ButtonNextstate digitalRead4) // switch is connected to pin Send serial message indicating button press 7 Indicate button has been pressed. Send serial message indicating button released // Indicate button released case 2: end of switch Lab Assignment: Prelab: Write the program described in the program section. You are required to create the header file, with the function calls described above. You will need to read the button in later labs. Lab 5: 1) Download and demonstrate the program in the prelab. Your demonstrations should be done suclh that you verify that the messages are only sent once when the button is pressed and released. 2) Using the Analog Discovery 2, capture the timing of the debounce operation that will show on the LED (Pin 13) Include a screen capture that shows the time that pin 13 is high. The time base on the Analog Discovery should be set such that the pulse on pin 13, occupies about % of display Program Structure: Create a separate file named ButtonDebounce.h and in it write the following code. 2 of 3 declare ButtonStates Global variable holding status of button Should use enum to set states as 7 Buttonidle, ButtonMait, ButtonHigh declare ButtonTine unsigned long to hold time to debounce Switch int Buttoninitialize O /I funct i on to set up system to read button presses set pin 4 to be an input set ButtonState to Idle State pinHode (4, INPUT // end of Buttoninitialize int ButtonNextState( input Idle: tunction that is to be called in loop to service the awitch awitch based on ButtonState State where nothing has been happening. if input is low, ButtonTine-millis(); // Record tine of high to low transition. set ButtonState to Wait /7 Hove to Wait state Turn on LED Pin 13 high used for debugging Wait: // Button has gone low and ve are waiting for Lt to remain low for 5 mi11econds t input ia high lse &E (milloo-time>5r s mLseconds has passed t button has gone high Reset back to Idle set Buttonstate to Idle set ButtonState to Lou Turn off LED return 1 Move to low state Pin 13 low alsoused for debugging / indicating that button has been pressed Once button released Indicate that the button has been released Low: / Button is low and has been so for 5 mi111 seconds t input is high set Buttonstate to Idle:Goback to Idle state return 2 end of switch return 0 1/ By default return 0 Indicating nothing is happening End of Button Next state Lab 5: 1) Download and demonstrate the program in the prelab. Your demonstrations should be done such that you verify that the messages are only sent once when the button is pressed and released. 2) Using the Analog Discovery 2, capture the timing of the debounce operation that will show on the LED (Pin 13). Include a screen capture that shows the time that pin 13 is high. The time base on the Analog Discovery should be set such that the pulse on pin 13, occupies abou1% of display. ECE 241 Lab 5 Spring 2019 Points: 20 Question: What was the time you observed on pin 13, and what is the relative error between it and the 5 milliseconds it was intended to be? RelError5 S where Ar is measured in milliseconds

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students also viewed these Databases questions

Question

Define the term financial services.

Answered: 1 week ago

Question

Distinguish between filtering and interpreting. (Objective 2)

Answered: 1 week ago