collectgarbage() local throttleInput local throttleMin local throttleMax local resetSwitch local runtime100 local exponent local lcdBW=false local timeCountOld local timeCountSaved local blink=false local runtime=0 local capacityAlarm={80,60,40,20,10,5,4,3,2,1,0} local alarmIndex=1 local throttleText="-" local consumptionText="-" local runtimeText="-" local capacityText="-" local function round(value) return math.floor(value+0.5) end local function printTelemetryBW() lcd.drawText(55-(lcd.getTextWidth(FONT_BIG,runtimeText)),0,runtimeText,FONT_BIG) lcd.drawText(145-(lcd.getTextWidth(FONT_BIG,capacityText)),0,capacityText,FONT_BIG) if runtime100>0 then if runtime0 then if runtime0 then runtime=0 alarmIndex=1 end end if throttleInput then throttle=system.getInputsVal(throttleInput) if throttlethrottleMax then throttleMax=throttle system.pSave("throttleMax",throttleMax) end throttle=(throttle-throttleMin)/(throttleMax-throttleMin) throttleText=string.format("%d%%",throttle*100) consumption=throttle^(0.1*exponent) consumptionText=string.format("%d%%",consumption*100) runtime=runtime+0.001*(timeCount-timeCountOld)*consumption runtimeText=string.format("%ds",runtime) if timeCount-timeCountSaved>=5000 then timeCountSaved=timeCount system.pSave("runtime",runtime) end if runtime100>0 then local capacity=round((runtime100-runtime)/runtime100*100) capacity=math.max(capacity,0) capacityText=string.format("%d%%",capacity) if alarmIndex<=#capacityAlarm then if capacity<=capacityAlarm[alarmIndex] then system.playNumber(capacity,0,"%","Capacity") alarmIndex=alarmIndex+1 end end else capacityText="-" end end timeCountOld=timeCount collectgarbage() end collectgarbage() return {init=init,loop=loop,author="LD",version="1.1",name="Motor Capacity Timer"}