ME 305
Functions | Variables
BlinkingLED.py File Reference

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())
 

Detailed Description

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

Author
Ryan Dean
Zachary Hendrix
Date
1/17/2022

Function Documentation

◆ onButtonPressCallback()

def BlinkingLED.onButtonPressCallback (   IRQ_src)

Callback function when button is pressed.

From user pressing the button, changing state of buttonPressed variable

Parameters
IRQ_srcThis is a reference the Nucleo that caused the interrupt to occur
Returns
No value is returned in a callback function since this was called by the MicroPython interrupt system

◆ SawWave()

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.

Parameters
tCurrent instant in time in miliseconds
Returns
Duty cycle percentage of LED

◆ SineWave()

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.

Parameters
tCurrent instant in time in miliseconds
Returns
Duty cycle percentage of LED

◆ SquareWave()

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.

Parameters
tCurrent instant in time in miliseconds
Returns
Duty cycle percentage of LED

Variable Documentation

◆ ButtonInt

BlinkingLED.ButtonInt
Initial value:
1= pyb.ExtInt(pinC13, mode=pyb.ExtInt.IRQ_FALLING,
2 pull=pyb.Pin.PULL_NONE,
3 callback = onButtonPressCallback)

Object that assoociates callback function to pin with external interrupt.

◆ pinA5

BlinkingLED.pinA5 = pyb.Pin(pyb.Pin.cpu.A5)

pyb.Pin object corresponding to pin number A5.


◆ t2ch1

BlinkingLED.t2ch1 = tim2.channel(1, pyb.Timer.PWM, pin=pinA5)

pyb.Timer channel object created.

Configures channel to Pulse Width Modulation mode on pinA5.

◆ tim2

BlinkingLED.tim2 = pyb.Timer(2, freq = 20000)

pyb.Timer class setting LED blinking frequency.

Sets the LED blinking frequency to 20000Hz.