### Jenny's Strobe, Jenny List sep 2019, borowing from the work of others especially the flashlight egg.
### Left/Right: Brightness
### Up/Down: speed
### Todo: need some kind of display time option

import rgb
import deepsleep
import buttons, defines
import time

brightness = rgb.getbrightness()
rgb.clear()
rgb.brightness(brightness)

rgb.disablecomp()
import display

color_ON = 0xFFFFFF ### white
color_OFF = 0x000000 ### black
flashdelay = 0.05 ### 2x this = 100mS
increment = 0.005 ### each button press adds thisx2.
direction = 0

UP, DOWN, LEFT, RIGHT = defines.BTN_UP, defines.BTN_DOWN, defines.BTN_LEFT, defines.BTN_RIGHT
A, B = defines.BTN_A, defines.BTN_B

def input_up(pressed):
    global direction
    direction = UP

def input_down(pressed):
    global direction
    direction = DOWN

def input_left(pressed):
    global direction
    direction = LEFT

def input_right(pressed):
    global direction
    direction = RIGHT

def input_B(pressed):
    global direction
    direction = B
	
def input_A(pressed):
    global direction
    direction = A
	
def oneflash():
	display.drawFill(0xFFFFFF)
	display.flush()
	time.sleep(flashdelay)
	display.drawFill(0x000000)
	display.flush()
	time.sleep(flashdelay)

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)


while direction != B:
  oneflash()
  if direction == DOWN:
    if flashdelay >= increment:
      flashdelay = flashdelay - increment
      print(flashdelay)
      direction = 0
  if direction == UP:
    flashdelay = flashdelay + increment
    print(flashdelay)
    direction = 0
  if direction == LEFT:
    if brightness > 3:
      brightness=brightness-1
      rgb.brightness(brightness)
      print(brightness)
      direction = 0
  if direction == RIGHT:
    if brightness < 32:
      brightness=brightness+1
      rgb.brightness(brightness)
      print(brightness)
      direction = 0

deepsleep.reboot()