import display
import mch22
from audio import play
import buttons
from time import sleep
from machine import Pin
from neopixel import NeoPixel


powerPin = Pin(19, Pin.OUT)
dataPin = Pin(5, Pin.OUT)
np = NeoPixel(dataPin, 5)
powerPin.on()


def on_home_btn(pressed):
  if pressed:
    mch22.exit_python()


def change_buttons(color_tuple):
    np[0] = color_tuple
    np[1] = color_tuple
    np[2] = color_tuple
    np[3] = color_tuple
    np[4] = color_tuple
    np.write()
    

display.drawPng(0,0,"/apps/python/balzak/balzak.png")
display.flush()
play('/apps/python/balzak/audio.mp3', volume=50)


buttons.attach(buttons.BTN_HOME, on_home_btn)

while True:
    change_buttons((0,0,0)) 
    sleep(0.2)
    change_buttons((255,0,0))
    sleep(0.2)
    change_buttons((0,0,0))
    sleep(0.2)
    change_buttons((0,255,0))
    sleep(0.2)
    change_buttons((0,0,0))
    sleep(0.2)
    change_buttons((0,0,255))
    sleep(0.2)

