ME 305
|
Creates various blinking patterns of LED on Nucleo-L476RG. More...
Functions | |
def | BlinkingLED.onButtonPressCallback (IRQ_src) |
Callback function when button is pressed. More... | |
def | BlinkingLED.SquareWave (t) |
Outputs square wave pattern. More... | |
def | BlinkingLED.SineWave (t) |
Outputs sine wave pattern. More... | |
def | BlinkingLED.SawWave (t) |
Outputs saw wave pattern. More... | |
Variables | |
bool | BlinkingLED.buttonPressed = False |
int | BlinkingLED.state = 0 |
Variable used to identify which LED pattern program currently in. | |
BlinkingLED.pinA5 = pyb.Pin(pyb.Pin.cpu.A5) | |
pyb.Pin object corresponding to pin number A5. More... | |
BlinkingLED.tim2 = pyb.Timer(2, freq = 20000) | |
pyb.Timer class setting LED blinking frequency. More... | |
BlinkingLED.t2ch1 = tim2.channel(1, pyb.Timer.PWM, pin=pinA5) | |
pyb.Timer channel object created. More... | |
BlinkingLED.pinC13 = pyb.Pin(pyb.Pin.cpu.C13) | |
pyb.Pin object corresponding to pin number C13. | |
BlinkingLED.ButtonInt | |
Object that assoociates callback function to pin with external interrupt. More... | |
int | BlinkingLED.g = 0 |
BlinkingLED.now = time.ticks_ms() | |
def | BlinkingLED.brt = SquareWave(time.ticks_ms()) |
Creates various blinking patterns of LED on Nucleo-L476RG.
The program uses a button located on the Nucleo to interact with the user through a PuTTY interface. On startup, the program will welcome the user with instructions on how to operate the program. By pressing the button, the user can then cycle between three different waveforms; Square Wave, Sine Wave, and Saw Wave. Once the button is pressed, the wave type will display on the PuTTY interface. The waves will cycle infinitely until the program is terminated using Ctrl+C.
See code repository for this lab: https://bitbucket.org/rdeanr/me305/src/master/Lab1/
See Short Demo Video Here: https://vimeo.com/user164074360/review/668107171/277bbe74f7
def BlinkingLED.onButtonPressCallback | ( | IRQ_src | ) |
Callback function when button is pressed.
From user pressing the button, changing state of buttonPressed variable
IRQ_src | This is a reference the Nucleo that caused the interrupt to occur |
def BlinkingLED.SawWave | ( | t | ) |
Outputs saw wave pattern.
Continuously receives value of miliseconds passed in Nulceo and is subtracted by a fixed reference time determined at instant of button press. Modulo division is then performed by the required time interval. This is converted into the appropriate timing. The output results is a linear increase in duty cycle percentage until 100% duty cycle is reached. The duty cycle then resets and linearlly increases again over and over at the appropriate frequency.
t | Current instant in time in miliseconds |
def BlinkingLED.SineWave | ( | t | ) |
Outputs sine wave pattern.
Continuously receives value of miliseconds passed in Nulceo and is subtracted by a fixed reference time determined at instant of button press. The output of this substraction is converted into rad/s and passed into a sinwave function that osciallates between 0 and 1. This is multiplied by 100 to get a duty cycle percentage.
t | Current instant in time in miliseconds |
def BlinkingLED.SquareWave | ( | t | ) |
Outputs square wave pattern.
Continuously receives value of miliseconds passed in Nulceo and compares it to a fixed reference time determined at instant of button press. These times are compared and instantaneously change the duty cycle of the LED using pulse width modulation from 0% to 100% every second. Function only continues when 1 second has passed.
t | Current instant in time in miliseconds |
BlinkingLED.ButtonInt |
Object that assoociates callback function to pin with external interrupt.
BlinkingLED.pinA5 = pyb.Pin(pyb.Pin.cpu.A5) |
pyb.Pin object corresponding to pin number A5.
BlinkingLED.t2ch1 = tim2.channel(1, pyb.Timer.PWM, pin=pinA5) |
pyb.Timer channel object created.
Configures channel to Pulse Width Modulation mode on pinA5.
BlinkingLED.tim2 = pyb.Timer(2, freq = 20000) |
pyb.Timer class setting LED blinking frequency.
Sets the LED blinking frequency to 20000Hz.