Cycle 3 modes of LED flashing by pressing Blue Button. More...
Functions | |
def | button_led.SQUARE () |
Toggles LED on for .5 seconds and then off for .5 seconds while in loop. More... | |
def | button_led.SINE () |
Displays a sine wave-like pattern through the LED while in a loop. More... | |
def | button_led.SAWTOOTH () |
Displays a sawtooth-like pattern through the LED while in a loop. More... | |
def | button_led.onButtonPressFCN (IRQ_src) |
Callback function for when the blue button is pressed. More... | |
Variables | |
button_led.pinC13 = pyb.Pin (pyb.Pin.cpu.C13) | |
Object for the Blue Button to be referenced. | |
button_led.pinA5 = pyb.Pin (pyb.Pin.cpu.A5) | |
Object for the LED to be referenced. | |
button_led.tim2 = pyb.Timer(2, freq = 20000) | |
Timer object that is used to track the time elapsed. | |
button_led.t2ch1 = tim2.channel(1, pyb.Timer.PWM, pin=pinA5) | |
Channel object to enable LED with PWM. | |
int | button_led.state = 0 |
Variable to track the state of the finite state machine. | |
int | button_led.state_prompt_reset = 1 |
State prompt variable used to prompt user in each state transition. | |
int | button_led.button_var = 0 |
Object used to track when the blue button is pressed. | |
button_led.buttonInt = pyb.ExtInt(pinC13, mode=pyb.ExtInt.IRQ_FALLING, pull=pyb.Pin.PULL_NONE, callback=onButtonPressFCN) | |
Defined interrupt object for when the blue button is pressed via IRQ_FALLING. | |
button_led.square_start = utime.ticks_ms() | |
Starting timer for Square wave. | |
button_led.sine_start = utime.ticks_ms() | |
Starting timer for Sine wave. | |
button_led.sawtooth_start = utime.ticks_ms() | |
Starting timer for Sawtooth wave. | |
Cycle 3 modes of LED flashing by pressing Blue Button.
This program runs with 4 states. Once turned on, there is a prompt that welcomes the user and describes how to use the code by pressing the blue button on the Nucleo. The state described above is state 0 and the LED is off. Once the user wants to leave state 0, they press the blue button to enter state 1, the square flashing wave (similar to a toggle). Then, the user can press the blue button again to enter state 2 which is a sine wave flashing. If the blue button is pressed again, the state turns to 3 and a sawtooth pattern is displayed on the LED. A last press of the blue button will take the user back to the initial LED off state. To leave this program the user must press Ctrl+C. Source code here: https://bitbucket.org/ColeSheedy/me-305-work-repository/src/master/LabWork/Lab2/button_led.py Link to video: https://youtu.be/32bShSiCzkU
def button_led.onButtonPressFCN | ( | IRQ_src | ) |
Callback function for when the blue button is pressed.
IRQ_src | Interrupt request from Blue Button. |
def button_led.SAWTOOTH | ( | ) |
Displays a sawtooth-like pattern through the LED while in a loop.
At time = 0, the LED intensity is 0% and increases to 100% over 1 second. This 1 second cycle will continuously sawtooth while in a loop.
def button_led.SINE | ( | ) |
Displays a sine wave-like pattern through the LED while in a loop.
At time = 0, the LED intensity is 50% to signify sin(0) being 50% of the amplitude. The wave cycles once every 10 seconds having a duty function = 50 * sin( timer * 2 * pi / 10 ) + 50.
def button_led.SQUARE | ( | ) |
Toggles LED on for .5 seconds and then off for .5 seconds while in loop.
At time = 0, the LED intensity is 0% and changes to 100% at .5 seconds and then back to 0% at 1 second. This 1 second cycle will wun continuously while in a loop.