from machine import Pin, PWM
import time
import _thread

red=PWM(Pin(15))
red.freq(5000)
red.duty_u16(65535)
blue=PWM(Pin(14))
blue.freq(5000)
blue.duty_u16(0)
green=PWM(Pin(13))
green.freq(5000)
green.duty_u16(0)

led0=Pin(16,Pin.OUT) #BR1
led1=Pin(17,Pin.OUT) #BR2
led2=Pin(18,Pin.OUT) #BR3
led3=Pin(19,Pin.OUT) #BR4
led4=Pin(20,Pin.OUT) #BR5
br=[led0,led1,led2,led3,led4] #br[i].toggle()

ledD=Pin(22,Pin.OUT) #blue LED
ledD.value(0)
ledA=Pin(21,Pin.OUT) #red LED
ledA.value(1)

button0=Pin(12,Pin.IN,Pin.PULL_DOWN) #control ledD&ledA
global button0_pressed
button0_pressed=False
def button0_reader_thread():
    global button0_pressed
    while True:
        if button0.value()==1:
            button0_pressed=True
        time.sleep(0.01)
_thread.start_new_thread(button0_reader_thread,())
while True:
    if button0_pressed==True:
        ledA.toggle()
        ledD.toggle()
        time.sleep(1)
    button0_pressed=False
    
button1=Pin(11,Pin.IN,Pin.PULL_DOWN) #control RGB and phases
global button1_pressed
global i
global p
button1_pressed=False
i=0
p=0
def button1_reader_thread():
    global button1_pressed
    while True:
        if button1.value()==1:
            button1_pressed=True
        time.sleep(0.01)
while True:
    if button1_pressed==True:
        

# button0 will handle switching ledD(blue) and ledA(red) to indicate player turn
# led0-4 indicate battle round (1-5), light when command phase starts
# RGB indicates battle phase (command, movement, psychic, shooting, charge, fight, morale)
# button1 change battle phase, loop through 7 phases;start start new command phase=new battle round