local function toMiles(kilometer)
    return kilometer * 0.621371
end    
    function update()    
        --carDigital MFD
        display.text{
            text = string.format("%06.0F", toMiles(car.distanceDrivenTotalKm)),
            pos = vec2(25, 243),
            letter = vec2(15, 28),
            font = "aria",
            color = rgbm(5,5,5,1), 
            width = 0.5,
            spacing = 0,
            alignment = -1.0
            }
            
            local gearText = tostring(car.gear) -- needs to be converted so that neutral and reverse display correctly (-1 = R, 0 = N)
            if car.gear == -1 then
                gearText = "R"
            end
            if car.gear == 0 then
                gearText = "N"
            end
            
            display.text {
                text = gearText,
                pos = vec2(485, 243),
                letter = vec2(20, 38),
                font = "aria",
                width = 0.5,
                alignment = 0,
                spacing = -1.0
            }    
            
            display.text{
                text = "mi",
                pos = vec2(120, 243),
                letter = vec2(15, 28),
                font = "aria",
                color = rgbm(5,5,5,1), 
                width = 0.5,
                spacing = 0,
                alignment = -1.0
                }
            
            display.text{
                text = "MPH",
                pos = vec2(180, 190),
                letter = vec2(30, 50),
                font = "aria",
                color = rgbm(5,5,5,1), 
                width = 0.5,
                spacing = 0,
                alignment = -1.0
                }
        
            local temperature = ac.getSimState().ambientTemperature
        
                display.text{
                    text = math.floor(temperature),
                    pos = vec2(30, 20),
                    letter = vec2(20, 38),
                    font = "aria",
                    color = rgbm(5,5,5,1)  
                    
                }  
                
                display.text{
                    text = "C",
                    pos = vec2(77, 22.5),
                    letter = vec2(18, 35),
                    font = "aria",
                    color = rgbm(5,5,5,1), 
                    width = 0.5,
                    spacing = 0,
                    alignment = -1.0
                    }

                digitCoords = {
                    -- define your coords here
                    vec2(155, 120), -- the leftmost digit
                    vec2(195, 120), -- the center digit
                    vec2(235, 120), -- the rightmost digit
                    vec2(175, 120), -- the center digit
                    vec2(215, 120) -- the rightmost digit
                }    
                
                -- preparing our table of speed digits
        local displayspeed = tostring(math.floor(toMiles(car.poweredWheelsSpeed))) -- math.floor rounds to the next full number
        local speedTable = {}
        for i = 1, string.len(displayspeed) do
            speedTable[i] = displayspeed:sub(i, i)
        end
        if string.len(displayspeed) == 1 then
            display.text {
                -- rightmost digit
                text = speedTable[1],
                pos = digitCoords[2],
                letter = vec2(50, 80),
                font = "aria",
                color = rgbm(5,5,5,1), 
                width = 0.5,
                spacing = 0,
                alignment = -1.0
            }
        elseif string.len(displayspeed) == 2 then
            display.text {
                -- rightmost digit
                text = speedTable[2],
                pos = digitCoords[5],
                letter = vec2(50, 80),
                font = "aria",
                color = rgbm(5,5,5,1), 
                width = 0.5,
                spacing = 0,
                alignment = -1.0
            }
            display.text {
                -- center digit
                text = speedTable[1],
                pos = digitCoords[4],
                letter = vec2(50, 80),
                font = "aria",
                color = rgbm(5,5,5,1), 
                width = 0.5,
                spacing = 0,
                alignment = -1.0
            }
        elseif string.len(displayspeed) == 3 then
            display.text {
                -- rightmost digit
                text = speedTable[3],
                pos = digitCoords[3],
                letter = vec2(50, 80),
                font = "aria",
                color = rgbm(5,5,5,1), 
                width = 0.5,
                spacing = 0,
                alignment = -1.0
            }
            display.text {
                -- center digit
                text = speedTable[2],
                pos = digitCoords[2],
                letter = vec2(50, 80),
                font = "aria",
                color = rgbm(5,5,5,1), 
                width = 0.5,
                spacing = 0,
                alignment = -1.0
            }
            display.text {
                -- leftmost digit
                text = speedTable[1],
                pos = digitCoords[1],
                letter = vec2(50, 80),
                font = "aria",
                color = rgbm(5,5,5,1), 
                width = 0.5,
                spacing = 0,
                alignment = -1.0
            }
    end
end