--[[alttitude graph, last flight times and heights on left, best flight times on right, timer 1 will be added to a total flight time at the bottom each time timer 1 is reset so I suggest you having timer 1 reset with each motor run, total flight time reset only when timer 2 goes up so using timer 2 for motor run is recommended so resetting it will reset total timer. person best is auto saved and held in radio after switch off by using gvar6 fm8 which needs to be set by YOU to -1000 for zero]]-- local MAXPOINTS = 200 local index = 0 local altitudes = {} local launches = {} local lastTime = 0 local lastTimerValue = 0 local lastMaxAltitude = 0 local time local altitude local lasttimer = 0 local timer = 0 local bestTime = 0 local bestTime1 = 0 local bestTime2 = 0 local counter = 0 local timer2 local score = 0 local timer3 = 0 local lasttimer2 = 0 local alt_id = getFieldInfo("altitude").id local a2_id = getFieldInfo("a2").id local altmax_id = getFieldInfo("altitude-max").id local pbest = (model.getGlobalVariable(5, 8)+1000)*5.99 local function init() for i=0,MAXPOINTS-1 do altitudes[i] = 0 end for i=0,5 do launches[i] = { duration=0, maxHeight=0 } end end local function background() time = getTime() altitude = getValue(alt_id) timer2 = model.getTimer(1) -- timing 100 = 1 second for graph moving 1000 gives about 30 mins graph if time > lastTime + 1000 then lastTime = time altitudes[index % MAXPOINTS] = altitude index = index+1 lasttimer2 = timer2.value lasttimer = timer end --reset if timer 2 goes up if (timer2.value > lasttimer2) then counter = 0 timer3 = 0 end timer = model.getTimer(0) if timer.value < lastTimerValue then launches[5] = launches[4] launches[4] = launches[3] launches[3] = launches[2] launches[2] = launches[1] launches[1] = launches[0] launches[0] = { duration=lastTimerValue, maxHeight=lastMaxAltitude } lastMaxAltitude = 0 counter = counter + 1 timer3 = timer3 + lastTimerValue end lastTimerValue = timer.value if altitude > lastMaxAltitude then lastMaxAltitude = altitude end if (launches[0].duration > bestTime2) and (launches[0].duration < bestTime1) then bestTime2 = launches[0].duration end if (launches[0].duration > bestTime1) and (launches[0].duration < bestTime) then bestTime2 = bestTime1 bestTime1 = launches[0].duration end if launches[0].duration > bestTime then bestTime2 = bestTime1 bestTime1 = bestTime bestTime = launches[0].duration end if launches[0].duration > pbest then pbest = launches[0].duration model.setGlobalVariable(5, 8, (pbest/5.99)-1000) end end local function run(event) background() print(event) -- timer draw lcd.drawTimer(90, 56, timer3, 0) lcd.drawTimer(125, 56, timer2.value, 0) -- left column lcd.drawTimer(5, 0, timer.value, MIDSIZE) local maxAltitude = getValue(altmax_id) lcd.drawNumber(79, 0, 3.28*maxAltitude, MIDSIZE) for i=0,5 do if launches[i].duration > 0 then lcd.drawTimer(10, 11+i*9, launches[i].duration, 0) lcd.drawNumber(70, 11+i*9, 3.28*launches[i].maxHeight , 0) end end -- right column -- a1 rx voltage lcd.drawNumber(205, 56, (getValue(a2_id)) * 10, PREC1) lcd.drawText(206, 56, "v", 0) if pbest > 5940 then lcd.drawTimer(135, 1, pbest, SMLSIZE+TIMEHOUR) else lcd.drawTimer(135, 1, pbest, SMLSIZE) end lcd.drawText( 120, 1, "pb", SMLSIZE) lcd.drawNumber(211, 0, 3.28*altitude, MIDSIZE) lcd.drawTimer(180, 21, bestTime, 0) lcd.drawTimer(180, 31, bestTime1, 0) lcd.drawTimer(180, 41, bestTime2, 0) lcd.drawText(155, 56, "n", SMLSIZE) lcd.drawText(182, 13, "Best", SMLSIZE) lcd.drawNumber(175, 56, counter, 0) -- middle column for i=0,MAXPOINTS-1 do local timeIdx local arrayIdx if index < MAXPOINTS then timeIdx = i arrayIdx = i else timeIdx = index+i arrayIdx = (index+i) % MAXPOINTS end local altitude = altitudes[arrayIdx] if altitude > 0 then local y = 63 - (58*altitude) / maxAltitude lcd.drawLine(1+i+1, y, 1+i+1, 58, SOLID, GREY_DEFAULT) end local bar = 0 if timeIdx % 12 == 0 then bar = 3 elseif timeIdx % 2 == 0 then bar = 2 end if bar > 0 and i