Luisa Chiu Portfolio
Lab0x01.py File Reference

Changes LED light patterns on the Nucleo L476 development board. More...

Functions

def Lab0x01.onButtonPressFCN (IRQ_src)
 This is a callback function that runs when the button is pressed. More...
 
def Lab0x01.reset_timer ()
 This is a function that resets the Current_Time, which is a measure of the duration for the wave. More...
 
def Lab0x01.update_timer ()
 This is a function that updates the Current_Time, which is a measure of the duration for the wave. More...
 
def Lab0x01.Update_SQW (Current_Time)
 This is a function that updates the LED brightness for the square wave pattern. More...
 
def Lab0x01.Update_STW (Current_Time)
 This is a function that updates the LED brightness for the sawtooth wave pattern. More...
 
def Lab0x01.Update_SW (Current_Time)
 This is a function that updates the LED brightness for the sine wave pattern. More...
 

Variables

 Lab0x01.pinA5 = pyb.Pin (pyb.Pin.cpu.A5)
 Creates a new pin object associated with pin A5 on the Nucleo. More...
 
 Lab0x01.pinC13 = pyb.Pin (pyb.Pin.cpu.C13)
 Creates a new pin object associated with pinC13 on the Nucleo. More...
 
 Lab0x01.tim2 = pyb.Timer(2,freq = 20000)
 Creates a timer object using timer 2. More...
 
 Lab0x01.t2ch1 = tim2.channel (1, pyb.Timer.PWM, pin=pinA5)
 Creates a timer channel object. More...
 
int Lab0x01.state = 0
 Creates an initial state condition. More...
 
int Lab0x01.runs = 0
 Sets the number of runs to 0. More...
 
int Lab0x01.press = 0
 Sets initial condition for button press callback to be False. More...
 
 Lab0x01.ButtonInt
 Registers the callback function and causes an interrupt when pressing the button. More...
 
 Lab0x01.startTime = utime.ticks_ms()
 An increasing millisecond counter with an arbitrary reference point. More...
 
 Lab0x01.stopTime = utime.ticks_ms()
 An increasing millisecond counter with an arbitrary reference point. More...
 
int Lab0x01.Current_Time = utime.ticks_diff(stopTime,startTime)/1000
 Duration between button presses in units of milliseconds. More...
 

Detailed Description

Changes LED light patterns on the Nucleo L476 development board.

State Transition Diagram

Link to Demonstration Video: https://youtu.be/anM4EopmLjM

Date
October 7, 2021

Function Documentation

◆ onButtonPressFCN()

def Lab0x01.onButtonPressFCN (   IRQ_src)

This is a callback function that runs when the button is pressed.

Using a variable that we assign with on (1) and off(0) values, we allow for the button to effectively switch on and off and move through the FSM.

Parameters
IRC_srcThis is the interrupt callback input that is called when the button is pressed.
Returns
'Press' variable is assigned the value 1.

◆ reset_timer()

def Lab0x01.reset_timer ( )

This is a function that resets the Current_Time, which is a measure of the duration for the wave.

The startTime variable is reset when this function is called.

◆ Update_SQW()

def Lab0x01.Update_SQW (   Current_Time)

This is a function that updates the LED brightness for the square wave pattern.

Using input Current_Time, this function creates a true/false argument that is satisfied by the listed expression and inequality.

Parameters
Current_Timerepresents the elapsed time between startTime and stopTime.
Returns
This function returns either value 0 or 100, and is used with pulse_width_percent to reflect LED brightness.

◆ Update_STW()

def Lab0x01.Update_STW (   Current_Time)

This is a function that updates the LED brightness for the sawtooth wave pattern.

Using input Current_Time, this function returns values that increase with time until reaching the value 1.

Parameters
Current_Timerepresents the elapsed time between startTime and stopTime.
Returns
This function returns increasing values until threshold is reached and is used with pulse_width_percent to reflect LED brightness.

◆ Update_SW()

def Lab0x01.Update_SW (   Current_Time)

This is a function that updates the LED brightness for the sine wave pattern.

This function returns sine values as a function of Current_Time and has a period of 10 seconds.

Parameters
Current_Timerepresents the elapsed time between startTime and stopTime.
Returns
This function returns sine values for the given period and is used with pulse_width_percent to reflect LED brightness.

◆ update_timer()

def Lab0x01.update_timer ( )

This is a function that updates the Current_Time, which is a measure of the duration for the wave.

The stopTime and Current_Time variables are updated when this function is called.

Variable Documentation

◆ ButtonInt

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

Registers the callback function and causes an interrupt when pressing the button.

Defines a variable for the interrupt request for pinC13 when the trigger is on a falling edge

◆ Current_Time

int Lab0x01.Current_Time = utime.ticks_diff(stopTime,startTime)/1000

Duration between button presses in units of milliseconds.

Calculates elapsed time between startTime and stopTime

◆ pinA5

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

Creates a new pin object associated with pin A5 on the Nucleo.

Defines a variable for pinA5 corresponding to LED light

◆ pinC13

Lab0x01.pinC13 = pyb.Pin (pyb.Pin.cpu.C13)

Creates a new pin object associated with pinC13 on the Nucleo.

Defines a variable for pinC13 corresponding to button press

◆ press

int Lab0x01.press = 0

Sets initial condition for button press callback to be False.

Defines a variable for the button press callback

◆ runs

int Lab0x01.runs = 0

Sets the number of runs to 0.

Defines a variable to keep track of runs

◆ startTime

Lab0x01.startTime = utime.ticks_ms()

An increasing millisecond counter with an arbitrary reference point.

Records the first time stamp in milliseconds

◆ state

int Lab0x01.state = 0

Creates an initial state condition.

Defines the starting state condition to be at state 0

◆ stopTime

Lab0x01.stopTime = utime.ticks_ms()

An increasing millisecond counter with an arbitrary reference point.

Records the second time stamp in milliseconds

◆ t2ch1

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

Creates a timer channel object.

Defines a variable for timer 2 channel 1 in relation to pinA5

◆ tim2

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

Creates a timer object using timer 2.

Defines a variable for a timer with a frequency of 20000 Hz