# John Kenneth Cabibil 3A - Microprocessor
# Initialisation
SWITCH = 13 # Set pin 13 as switch
RED = 4 # Set pin 4 as RED led
GREEN = 2 # Set pin 2 as GREEN led
BLUE = 15 # Set pin 15 as BLUE led
YELLOW = 5 # Set pin 5 as YELLOW led
# Set-up program
from machine import Pin
from time import sleep
switch = Pin(SWITCH, Pin.IN) # Set SWITCH as input
red_led = Pin(RED, Pin.OUT) # Set RED LED as output
green_led = Pin(GREEN, Pin.OUT) # Set GREEN LED as output
blue_led = Pin(BLUE, Pin.OUT) # Set BLUE LED as output
yellow_led = Pin(YELLOW, Pin.OUT) # Set YELLOW LED as output
# Void loop
while True: # Code to be executed over and over again
if switch.value() == 0: # Condition 1: when switch is off
red_led.on() # RED LED turns on
green_led.on() # GREEN LED turns on
blue_led.on() # BLUE LED turns on
yellow_led.off() # YELLOW LED turns off
sleep(0.8) # ms delay for BLUE and YELLOW LED blinking
blue_led.off() # BLUE LED turns off
yellow_led.on() # YELLOW LED turns on
sleep(0.8) # ms delay for BLUE and YELLOW LED blinking
else: # Condition 2: when switch is on
green_led.on() # GREEN LED turns on
blue_led.on() # BLUE LED turns on
yellow_led.on() # YELLOW LED turns on
red_led.off() # RED LED turns off
sleep(0.8) # ms delay for RED and GREEN LEDs blinking
green_led.off() # GREEN LED turns off
red_led.on() # RED LED turns on
sleep(0.8) # ms delay for RED and GREEN LEDs blinking