Lucas Murray ME 305 Portfolio
Functions | Variables
ME305_Lab0x01.py File Reference

Program to change the output of an LED light when a button is pressed. More...

Functions

def ME305_Lab0x01.onButtonPressFCN (IRQ_src)
 Recognizes the external input of the button being pressed. More...
 
def ME305_Lab0x01.Square (elapsedTime)
 Calculates and returns the values for a square wave. More...
 
def ME305_Lab0x01.Sine (elapsedTime)
 Calculates and returns the values for a sine wave. More...
 
def ME305_Lab0x01.Saw (elapsedTime)
 Calculates and returns the values for a saw wave. More...
 

Variables

 ME305_Lab0x01.C13 = pyb.Pin(pyb.Pin.cpu.C13)
 Allocates the pin located at C13 on the MCU to the variable C13.
 
 ME305_Lab0x01.A5 = pyb.Pin(pyb.Pin.cpu.A5, pyb.Pin.OUT_PP)
 Allocates the pin located at A5 on the MCU to the variable A5.
 
 ME305_Lab0x01.ButtonInt
 Makes a callback to C13 when an external input is recieved. More...
 
 ME305_Lab0x01.tim2 = pyb.Timer(2, freq=2000)
 Creates a timer object using timer 2 with a trigger at 2000Hz.
 
 ME305_Lab0x01.t2ch1 = tim2.channel(1, pyb.Timer.PWM, pin=A5)
 Initiates a channel object for pin A5.
 
int ME305_Lab0x01.count = 0
 Exists as a placeholder for the state number and allows it change.
 
bool ME305_Lab0x01.buttonPressed = False
 
 ME305_Lab0x01.start_time = time.ticks_ms()
 Records the time at which the state changes.
 
 ME305_Lab0x01.current_time = time.ticks_ms()
 Continuously records and replaces the current time.
 
int ME305_Lab0x01.waveTime = time.ticks_diff(current_time, start_time) / 1000
 Records the difference between current and start time.
 
def ME305_Lab0x01.brightness = Square(waveTime) * 100
 Constantly records and replaces the brightness value.
 

Detailed Description

Program to change the output of an LED light when a button is pressed.

The program is created for an STM NUCLEO L476 microcontroller to recognize the button input at pin C13 and use it to create an interrupt request that switches the LED light output at pin A5.

See a video of the code output on the microcontroller at https://drive.google.com/file/d/15uv9jhiehYf324MMxv1OPe8x68T7BTZ5/view?usp=sharing Source Code: https://bitbucket.org/lmurray03/me305_lucas_murray/src/master/Lab%200x01/ME322%20Lab0x01.py

Author
Max Cassady
Lucas Murray
Date
(1/18/2022)

Function Documentation

◆ onButtonPressFCN()

def ME305_Lab0x01.onButtonPressFCN (   IRQ_src)

Recognizes the external input of the button being pressed.

Takes the interrupt request passed by the ButtonInt variable when the button is pressed and changes the buttonPressed value to True

Parameters
IRQ_srcinterrupt request from source

◆ Saw()

def ME305_Lab0x01.Saw (   elapsedTime)

Calculates and returns the values for a saw wave.

Parameters
elapsedTimeTime elapsed since the button was last pressed
Returns
The y-value of the saw wave with respect to time

◆ Sine()

def ME305_Lab0x01.Sine (   elapsedTime)

Calculates and returns the values for a sine wave.

Parameters
elapsedTimeTime elapsed since the button was last pressed
Returns
The y-value of the sine wave with respect to time

◆ Square()

def ME305_Lab0x01.Square (   elapsedTime)

Calculates and returns the values for a square wave.

Parameters
elapsedTimeTime elapsed since the button was last pressed
Returns
The y-value of the square wave with respect to time

Variable Documentation

◆ ButtonInt

ME305_Lab0x01.ButtonInt
Initial value:
1= pyb.ExtInt(C13, mode=pyb.ExtInt.IRQ_FALLING,
2 pull=pyb.Pin.PULL_NONE, callback=onButtonPressFCN)

Makes a callback to C13 when an external input is recieved.