import defines, rgb, buttons, system
from time import sleep

UP, DOWN, LEFT, RIGHT = defines.BTN_UP, defines.BTN_DOWN, defines.BTN_LEFT, defines.BTN_RIGHT
direction = ''
mode = 1

rainbow_colors = [(148, 0, 211), (75, 0, 130), (0, 0, 255), (0, 255, 0), (255, 255, 0), (255, 127, 0), (255, 0, 0)]


def input_down(pressed):
    if not pressed:
        return
    global mode
    if mode == 1:
        print("Switching to mode " + str(2))
        mode = 2
    elif mode == 2:
        print("Switching to mode " + str(1))
        mode = 1


def input_B(pressed):
    global direction
    print("Exiting")
    direction = defines.BTN_B


buttons.register(defines.BTN_DOWN, input_down)
buttons.register(defines.BTN_B, input_B)


def rainbow_text(msg, total_duration=2):
    for color in rainbow_colors:
        rgb.clear()
        rgb.text(msg, color)
        sleep(total_duration / len(rainbow_colors))


def chill_lounge():
    rainbow_text("NICKS")
    rainbow_text("CHILL")
    rainbow_text(" CLUB")
    rainbow_text(" \o/ ")


def now_opened():
    rainbow_text("OPEN")
    rainbow_text(" NOW")


while direction != defines.BTN_B:
    rgb.clear()

    if mode == 1:
        chill_lounge()
    elif mode == 2:
        now_opened()

system.reboot()