My Project
nucleo_LED.py File Reference

Nucleo's LED transitions between 3 pulse wave cycles. More...

Functions

def nucleo_LED.myCallback (IRQ_source)
 interrupt callback called when blue user button is pushed More...
 

Variables

int nucleo_LED.myVar = 0
 setting global variable equal to 0
 
int nucleo_LED.start = 0
 set start time to zero
 
 nucleo_LED.pinA5 = pyb.Pin (pyb.Pin.cpu.A5)
 Connecting to pinA5 to control LD2 LED.
 
 nucleo_LED.tim2 = pyb.Timer(2, freq = 20000)
 create object using timer 2, trigger at 20000 hz (cycle/sec)
 
 nucleo_LED.t2ch1 = tim2.channel(1, pyb.Timer.PWM, pin=pinA5)
 Set up timer channel for LD2 LED.
 
 nucleo_LED.pinC13 = pyb.Pin (pyb.Pin.cpu.C13)
 Define pin object for PC13 - for blue user button.
 
 nucleo_LED.ButtonInt = pyb.ExtInt(pinC13, mode=pyb.ExtInt.IRQ_FALLING,pull=pyb.Pin.PULL_NONE, callback=myCallback)
 Associate the callback function with the pin by setting up an external interrupt.
 
int nucleo_LED.state = 0
 Setting state to initial state.
 
 nucleo_LED.start1 = utime.ticks_ms()
 start recording time for state 1
 
tuple nucleo_LED.duration = (utime.ticks_diff(start1,start)/1000)
 find difference of time (ms->sec) between button click and state start
 
int nucleo_LED.duty = 100*(duration%1)
 percentage of LED brightness
 
 nucleo_LED.start2 = utime.ticks_ms()
 start recording time for state 2
 
 nucleo_LED.start3 = utime.ticks_ms()
 start recording time for state 3
 
 nucleo_LED.mode
 
 nucleo_LED.IRQ_FALLING
 
 nucleo_LED.pull
 
 nucleo_LED.PULL_NONE
 
 nucleo_LED.callback
 

Detailed Description

Nucleo's LED transitions between 3 pulse wave cycles.

Implements a finite state machine, shown below, to simulate the behavior of a Nucleo's LED (LD2) transtioning between three pulse cycles (Square,Sine,Saw-Tooth) by clicking on the blue user button on the Nucleo. The link to the code can be found here: https://bitbucket.org/mzaman01/me305_labs/src/master/Lab%202/nucleo_LED.py The link to the video can be found here: https://www.youtube.com/watch?v=sSyAD_bxfh0

Nucleo LED Finite State Transition Diagram
Author
Maisha Zaman
Date
February 4th, 2021

Function Documentation

◆ myCallback()

def nucleo_LED.myCallback (   IRQ_source)

interrupt callback called when blue user button is pushed

Parameters
IRQ_srcthe interrupt request state