from machine import Pin
import time
from random import randint

btn=Pin(12,Pin.IN,Pin.PULL_UP)


#LEDs
green=Pin(17,Pin.OUT)
yellow=Pin(14,Pin.OUT)
red=Pin(15,Pin.OUT)

#start with lights off
green.off()
yellow.off()
red.off()

#2 modes, manual and random
# TODO set up selector between manual (button op) and random time (randint)
toggle=Pin(pin,Pin.IN,Pin.PULL_UP)

def measure_tog():
    tVal=toggle.value()
    time.sleep(1)
    return tVal
if tVal=1:
    #run automatically, random.randint(?,?), 1 LED color at a time
    
if tVal=0:
    #use button to change LED
    green.on()
    yellow.off()
    red.off()

###CREATE MAIN LOOP###
""" use toggle to determine which control to give (auto or manual)
probably check toggle status before running any subroutines, need to check status of this item first,
and detect fresh changes on Pin as they come in, IRQ
if auto, use random times to switch between lights, turning on new light, off old light
if manual, need to read for button presses and use that to move through lights
need to set up cases, OFF(no LED), RED(red only), YELLOW(yellow only), GREEN(green only)
"""

while tval=0:
    red.off()
    green.on()
    time.sleep(random.randint(5,60))
    green.off()
    yellow.on()
    time.sleep(random.randint(5,60))
    yellow.off()
    red.on()
    time.sleep(random.randint(5,60))