#imports necessary libraries
import machine
import utime
# SEtup Inptu and output pins
redLED = machine.Pin(2,machine.Pin.OUT)
greenLED = machine.Pin(4,machine.Pin.OUT)
yellowLED = machine.Pin(14,machine.Pin.OUT)
blueLED = machine.Pin(12,machine.Pin.OUT)
sw_input = machine.Pin(35,machine.Pin.IN)
currentTime =0
delayBlink = 1
prevValue = 0
def BlinkLED(led1,led2): # this funciton holds the blinking of LED
global currentTime #set value of currentTime to be accessed in this functions
global prevValue #set value of prevValue to be accessed in this functions
if(utime.time() >= currentTime): # test if utime.time() reached the value of currentTime
currentTime = delayBlink +currentTime # this will increment new value of currentTime with respect to delayBlink
print(currentTime)
# this will alternate the blink of LED
if(prevValue == 1):
led1.value(0)
led2.value(prevValue)
else:
led1.value(1)
led2.value(prevValue)
prevValue = led1.value()
def SteadyLED(led1,led2):# this will steady 1 whatever led is passed in the function
led1.value(1)
led2.value(1)
def loop(): # this is the function that will run in loop
print(sw_input)
# if-else statement to trigger the sw_input
# depending on the sw_input value, specific LED is passed in the functions to manipulate its state
if sw_input.value() == 1:
BlinkLED(blueLED,yellowLED)
SteadyLED(redLED,greenLED)
else:
BlinkLED(redLED,greenLED)
SteadyLED(blueLED,yellowLED)
while True:# this will execute a loop to run function loop()
loop()