from machine import Pin, Timer
#Initialize the onboard LED as ouput
led = Pin(2, Pin.OUT)
#Initialize timer_one. Used for toggeling the LED
timer_one = Timer(0)
#Initialize timer_two. Used for changing the State
timer_two = Timer(1)
#Initialize state variable. Used for changing the State
state = 1
toggle = 1
def BlinkLED(timer_one):
global toggle
if toggle == 1:
led.value(0)
toggle = 0
else:
led.value(1)
toggle = 1
def ChangeState(timer_two):
global state
if state == 1:
# 100mS Timer initialization
timer_one.init(freq=10, mode=Timer.PERIODIC, callback=BlinkLED)
state = state+1
elif state == 2:
# 250mS Timer initialization
timer_one.init(freq=4, mode=Timer.PERIODIC, callback=BlinkLED)
state = state+1
elif state == 3:
# 1000mS Timer initialization
timer_one.init(freq=1, mode=Timer.PERIODIC, callback=BlinkLED)
state = 1
else:
# Default state
# 100mS Timer initialization
state = 1
timer_one.init(freq=10, mode=Timer.PERIODIC, callback=BlinkLED)
# Initialize the timer one for first time
timer_one.init(freq=10, mode=Timer.PERIODIC, callback=BlinkLED)
state = state+1
#Subcequent timer states for 20 seconds interval
timer_two.init(freq=0.05, mode=Timer.PERIODIC, callback=ChangeState)