Mechatronics Portfolio
Logan Williamson's Mechatronics Portfolio and Documentation Repository
Functions | Variables
ME305_Lab0x01.py File Reference

This code can change brightness of LED in apparent sequences upon button press. More...

Functions

def ME305_Lab0x01.onButtonPressCallback (IRQ_src)
 
def ME305_Lab0x01.SquareWave (t)
 This function calculates brightness at a given t value fluctuating in a square wave. More...
 
def ME305_Lab0x01.SineWave (t)
 Function for Sine Wave Generation. More...
 
def ME305_Lab0x01.SawWave (t)
 Function for Saw Tooth Wave Generation. More...
 

Variables

 ME305_Lab0x01.button_Pin = pyb.Pin (pyb.Pin.cpu.C13)
 
 ME305_Lab0x01.LED_Pin = pyb.Pin (pyb.Pin.cpu.A5)
 
bool ME305_Lab0x01.buttonPressed = False
 buttonPressed set to boolean values used to observe whether button on pyboard is pressed More...
 
int ME305_Lab0x01.state = 0
 state used to transition between FSM state diagram, 4 states total More...
 
 ME305_Lab0x01.ButtonInt
 ButtonInt connects button press with pyboard input. More...
 
 ME305_Lab0x01.tim2 = pyb.Timer(2, freq = 20000)
 tim2 creates variable for connecting timer from the pyboard More...
 
 ME305_Lab0x01.t2ch1 = tim2.channel(1, pyb.Timer.PWM, pin=LED_Pin)
 tim2 creates variable for connecting timer to the LED on the pyboard More...
 
 ME305_Lab0x01.startTime = time.ticks_ms()
 startTime begins clock timer More...
 
 ME305_Lab0x01.t = time.ticks_diff(time.ticks_ms(),startTime)
 t is the time variable used in each wave function
 
def ME305_Lab0x01.brt = SquareWave(t)
 brt is the brightness calculated using the wave functions More...
 

Detailed Description

This code can change brightness of LED in apparent sequences upon button press.

Upon button press, LED shows different sequences: square, sine, and saw wave functions. Utilizes FSM state transition logic and integration.

Author
Logan Williamson
Brianna Roberts
Date
01/13/2022

Function Documentation

◆ SawWave()

def ME305_Lab0x01.SawWave (   t)

Function for Saw Tooth Wave Generation.

Function evaluates brightness percentage at given time for LED

Parameters
tInput value is t from clock generated in main
Returns
Returns brightness level evaluated at time t for LED to appear fluctuating in a sawtooth wave

◆ SineWave()

def ME305_Lab0x01.SineWave (   t)

Function for Sine Wave Generation.

Function evaluates brightness percentage at given time for LED

Parameters
tInput value is t from clock generated in main
Returns
Returns brightness level evaluated at time t for LED to appear fluctuating in a sine wave

◆ SquareWave()

def ME305_Lab0x01.SquareWave (   t)

This function calculates brightness at a given t value fluctuating in a square wave.

Function evaluates brightness percentage at given time for LED

Parameters
tInput value is time (t) from clock generated in main
Returns
Returns brightness level evaluated at time t for LED to appear fluctuating in a square wave

Variable Documentation

◆ brt

def ME305_Lab0x01.brt = SquareWave(t)

brt is the brightness calculated using the wave functions

brt (brightness) changes with each state transition it's a value between 0-100 given as a percentage. Used for LED to change the pulse width percent.

◆ ButtonInt

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

ButtonInt connects button press with pyboard input.

once button is pressed, initiates the onButtonPressCallback function and turns on (sets True) the buttonPressed variable

◆ buttonPressed

bool ME305_Lab0x01.buttonPressed = False

buttonPressed set to boolean values used to observe whether button on pyboard is pressed

buttonPressed is set to either true or false. Only set to true momentarily upon button press, once state is changed, button is immediately reset to False awaiting for next button press

◆ startTime

ME305_Lab0x01.startTime = time.ticks_ms()

startTime begins clock timer

startTime is reset at beginning of each state transition.

◆ state

int ME305_Lab0x01.state = 0

state used to transition between FSM state diagram, 4 states total

four states exist: 0, 1, 2, 3 states are transitioned upon button press. state 0 is the "off" or initialization state. state 1 causes LED to transition to square wave function state 2 causes LED to transition to sine wave function state 3 causes LED to transition to saw wave function

◆ t2ch1

ME305_Lab0x01.t2ch1 = tim2.channel(1, pyb.Timer.PWM, pin=LED_Pin)

tim2 creates variable for connecting timer to the LED on the pyboard

used to then change PWP on LED

◆ tim2

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

tim2 creates variable for connecting timer from the pyboard

used further in connecting to the LED pin