import rgb, buttons, defines, system, time

UP, DOWN, LEFT, RIGHT = defines.BTN_UP, defines.BTN_DOWN, defines.BTN_LEFT, defines.BTN_RIGHT
A, B = defines.BTN_A, defines.BTN_B

direction = -1
brightness = rgb.getbrightness()

def input_up(pressed):
	if pressed:
		print("Pressed UP")
		global direction
		direction = UP

def input_down(pressed):
	if pressed:
		print("Pressed DOWN")
		global direction
		direction = DOWN

def input_left(pressed):
	if pressed:
		print("Pressed LEFT")
		global direction
		direction = LEFT

def input_right(pressed):
	if pressed:
		print("Pressed RIGHT")
		global direction
		direction = RIGHT

def input_B(pressed):
	if pressed:
		print("Pressed B")
		global direction
		direction = B
	
def input_A(pressed):
	if pressed:
		print("Pressed A")
		global direction
		direction = A

buttons.register(UP, input_up)
buttons.register(DOWN, input_down)
buttons.register(LEFT, input_left)
buttons.register(RIGHT, input_right)
buttons.register(B, input_B)
buttons.register(A, input_B)

color = (0,0,255)
tekst = "<<- TwenSpace is OPEN"
status = 1
rgb.clear()
rgb.scrolltext(tekst,color)

while direction != B:
	print("Direction",direction)
	if direction == LEFT:
		if brightness > 3:
			brightness=brightness-1
			rgb.brightness(brightness)
			print(brightness)
			direction = -1
	if direction == RIGHT:
		if brightness < 32:
			brightness=brightness+1
			rgb.brightness(brightness)
			print(brightness)
			direction = -1
	if direction == UP:
		if status == 1:
			color = (255,0,0)
			tekst = "TwenSpace is GESLOTEN"
			status = 0
		else:
			color = (0,0,255)
			tekst = "<<- TwenSpace is OPEN"
			status = 1
		direction = -1
		rgb.clear()
		rgb.scrolltext(tekst,color)
	time.sleep(0.2)
system.reboot()