##Master control software:: ---------------------------------------------

Tnaught = time.time()
Fanstate = 0    #keep fan on/off noted
O2state = 0     #keep O2 on/off noted
fuelCount = 0   #track number of fuel additions
T1 = time.time()  #intital time note
dataB = []
Length = len(dataA) #length of dataA noted
initialText = Text(Point(-200,75),"Initializing...")
initialText.setFill('red')
n = 0
N = 1
while(N == 1):
    print "tick"
    time.sleep(.1)
    dT = time.time()-T1 #get time interval
    if dT >=5:
        T1 = time.time()
        getThermocouple(dataA) #if interval greater than 10 seconds, record thremocouple
    if len(dataA)>Length:
        Length = len(dataA)
        wipeGraph(graphArray)
        if len(dataA) > 20:
            plotArray(smooth(dataA),win)    #if more than one data point, and an increase in number of measurements, regraph the data
            Length = len(dataA)
        else:
            plotArray(dataA,win)
    x,y = checkMouse() #see if a command given
    B = getButton(x,y)
    if n < 20:
        n = n + 1
        B = 0 #locks out buttons for initialization period)
        initialText.draw(win)
        time.sleep(.1)
        initialText.undraw()
    if B == 1:
        #if fan button, toggle fan
        Fanstate = 1 - Fanstate
        if Fanstate == 1:
            fanOn()
            fanCircle.setFill("green")
            fanCircle.undraw()
            fanCircle.draw(win)
        elif Fanstate == 0:
            fanOff()
            fanCircle.setFill("red")
            fanCircle.undraw()
            fanCircle.draw(win)
    elif B == 2:
        #if O2 button, toggle O2
        O2state = 1 - O2state
        if O2state == 1:
            O2on()
            O2Circle.setFill("green")
            O2Circle.undraw()
            O2Circle.draw(win)
        elif O2state == 0:
            O2off()
            O2Circle.setFill("red")
            O2Circle.undraw()
            O2Circle.draw(win)
    elif B == 3:
        #if TC button, take a measurement
        getThermocouple(dataA)
    elif B == 4:
        #if fuel button, add fuel
        fuelAdd()
        fuelCount = fuelCount + 1
    elif B == 5:
        fanOff()
        O2off()
        saveData(dataB)
        win.close()
        N = 0

##End master control software:: ---------------------------------------------