![]() |
Mechatronics Portfolio
Logan Williamson's Mechatronics Portfolio and Documentation Repository
|
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... | |
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.
def ME305_Lab0x01.SawWave | ( | t | ) |
Function for Saw Tooth Wave Generation.
Function evaluates brightness percentage at given time for LED
t | Input value is t from clock generated in main |
def ME305_Lab0x01.SineWave | ( | t | ) |
Function for Sine Wave Generation.
Function evaluates brightness percentage at given time for LED
t | Input value is t from clock generated in main |
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
t | Input value is time (t) from clock generated in main |
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.
ME305_Lab0x01.ButtonInt |
ButtonInt connects button press with pyboard input.
once button is pressed, initiates the onButtonPressCallback function and turns on (sets True) the buttonPressed variable
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
ME305_Lab0x01.startTime = time.ticks_ms() |
startTime begins clock timer
startTime is reset at beginning of each state transition.
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
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
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