Question: Solve the following using Python: TODO: Import the utime functions and Pin class object that you need here! EE 2450 Module 2 Summative Assignment For

Solve the following using Python:

"""TODO: Import the utime functions and Pin class object that you need here!

""""""EE 2450 Module 2 Summative Assignment

For this summative assignment, you will complete/write the below functions in Python

.I have written TODOs below for different function signatures or purposes

For the C-task of this program, you will implement a program where:

1. a user, upon board reset, will be prompted to input a "heart rate" in beats per minute (60-80 bpm is the standard resting heart rate for more adults).

2. the microcontroller will make a "heartbeat" (lub-DUB, or a dim flash followed by a bright flash) at the heart rate that the user put in.

3. this heartbeat will continue until the user resets the board by hitting the stop sign icon.

This time, since you are familiar with writing programs, think about how to structure

your program by adding functions to achieve certain tasks, such as two functions, one for

flashing the LED pin dim, and one for flashing the LED pin bright. I have not added all

the functions that need to be written, so think about which functions you can add so that your

code is readable and organized, and try it out by adding them!

Note: do not be afraid to experiment!! You won't be able to break your computer.

"""

def get_user_heart_rate() -> int:

""" get_user_heart_rate() asks the console user to enter the heart rate of their heart beat.

example: get_user_heart_rate() -> 60 # (this is assuming the user enters 60 atthe prompt and hits enter)

example: get_user_heart_rate() -> 40 # (this is assuming the user enters 40 atthe prompt and hits enter)

:returns: integer of the time in seconds that the user wishes the LED to be on for

"""

user_heart_rate = """ TODO: Finish this line """

return user_heart_rate

def convert_heart_rate_to_ms_period(heart_rate: int) -> int:

""" convert_heart_rate_to_ms_period(heart_rate) converts the heart rate to period between beats in milliseconds. Since heart rates are given in beats per minute, the beats per second can be calculated by dividing by 60.

Then, the period can be found in seconds by flipping the value and multiplying by 1000:

hr_bps = heart_rate / 60

period_s = 1 / hr_bps

period_ms = 1000 * period_s

:param: heart_rate: heart rate in beats per minute (integer)

:returns: period between heart beats in millseconds

"""

return 60000 / heart_rate # simplified version of the operations above """

TODO: write the function signature above (what should the parameter data type be?)

single_heartbeat(pin_to_led) is the function that will run one cycle of the heartbeat on pin_to_led.

This single heartbeat will go "lub-DUB" (dim flash followed by a bright flash).

This is supposed to mimic the action of the heart, where the smaller atrium contracts first,

followed by contraction of the larger ventricle. For an example of this, see: https://en.wikipedia.org/wiki/File:Flow_through_the_Heart.webm

Assume that the dim flash should be on for 100 ms, and the bright flash should be on for 200 ms.

HINT: You will need to write two functions above this function, one for each flash type, that use PWM.

Side note: Don't worry about the fact (if you happen to be an EMT) that the lubis not actually

tied to the atrium with heart sounds, as this is more just a fun kind of visual effect.

lub-DUB is actually heart sounds one can hear a result of the ventricle contracting and filling.

TODO: make sure to call this in main(), otherwise you will not see anything!

""" return

def main() -> None:

"""main() is the main function that will call other functions to implement your program.

For the C-task of this program, you will implement a program where:

1. a user, upon board reset, will be prompted to input a "heart rate" in beats per minute

(60-80 bpm is the standard resting heart rate for more adults).

2. the microcontroller will make a "heartbeat" (lub-DUB, or a dim flash followed by a bright flash)

at the heart rate that the user put in.

3. this heartbeat will continue until the user resets the board by hitting the stop sign icon. the above steps will generally be implemented by functions defined before the

main() function. """main()

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!