from machine import Pin #import pin from machine
import time #import time for delay
on = Pin(12, Pin.IN); #assign pin 12 to on as input
red = Pin(18, Pin.OUT); #assign pin 18 to red as output
green = Pin(5, Pin.OUT); #assign pin 5 to green as output
blue = Pin(4, Pin.OUT); #assign pin 4 to blue as output
yellow = Pin(2, Pin.OUT); #assign pin 2 to yellow as output
while True:
if on.value() == 1: #do if the parameter on = 1 is met
green.value(1) #turn on green
red.value(1) #turn on red
while on.value() == 1: #do while the parameter on = 1 is met
blue.value(1) #turn on blue
yellow.value(0) #turn off yellow
time.sleep(1) #wait for 1 second
blue.value(0) #turn off blue
yellow.value(1) #turn off yellow
time.sleep(1) #wait for 1 second
elif on.value() == 0: #do if the parameter on = 0 is met
blue.value(1) #turn on blue
yellow.value(1) #turn on yellow
while on.value() == 0: #do while the parameter on = 0 is met
red.value(1) #turn on red
green.value(0) #turn off green
time.sleep(1) #wait for 1 second
red.value(0) #turn off red
green.value(1) #turn on green
time.sleep(1) #wait for 1 second