from machine import Pin
import time

# Pin definitions
LED1_PIN = Pin(2, Pin.OUT)
LED2_PIN = Pin(3, Pin.OUT)
RGB1_R = Pin(4, Pin.OUT)
RGB1_G = Pin(5, Pin.OUT)
RGB1_B = Pin(6, Pin.OUT)
RGB2_R = Pin(7, Pin.OUT)
RGB2_G = Pin(8, Pin.OUT)
RGB2_B = Pin(9, Pin.OUT)
BAR_PINS = [Pin(10, Pin.OUT), Pin(11, Pin.OUT), Pin(12, Pin.OUT), 
            Pin(13, Pin.OUT), Pin(14, Pin.OUT), Pin(15, Pin.OUT)]

previous_time = 0
state = 0

def reset_all():
    """Turn off all LEDs"""
    LED1_PIN.value(0)
    LED2_PIN.value(0)
    RGB1_R.value(0)
    RGB1_G.value(0)
    RGB1_B.value(0)
    RGB2_R.value(0)
    RGB2_G.value(0)
    RGB2_B.value(0)
    for pin in BAR_PINS:
        pin.value(0)

# Initial setup
reset_all()

while True:
    current_time = time.ticks_ms()
    
    # Check if 2 seconds (2000ms) have passed
    if time.ticks_diff(current_time, previous_time) >= 2000:
        previous_time = current_time
        state = (state + 1) % 3
        reset_all()
    
    # State machine
    if state == 0:
        # Turn on LED1, RGB1_R, and first 3 LEDs of bar graph
        LED1_PIN.value(1)
        RGB1_R.value(1)
        for i in range(3):
            BAR_PINS[i].value(1)
    
    elif state == 1:
        # Turn on LED2, RGB2_G, and last 3 LEDs of bar graph
        LED2_PIN.value(1)
        RGB2_G.value(1)
        for i in range(3, 6):
            BAR_PINS[i].value(1)
    
    elif state == 2:
        # Turn on both LEDs, RGB1_B and RGB1_G, RGB2_B and RGB2_G, and all LEDs of bar graph
        LED1_PIN.value(1)
        LED2_PIN.value(1)
        RGB1_B.value(1)
        RGB1_G.value(1)
        RGB2_B.value(1)
        RGB2_G.value(1)
        for pin in BAR_PINS:
            pin.value(1)
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT