local white = rgb(1, 1, 1)
local red = rgb(1, 0.01, 0)
local last_displayed_rpm = 0
local time_since_last_update = 0
local REFRESH = 0.05  -- Adjust this value to control the refresh rate (e.g., 0.1 for 10 times per second)
local REV_LIMITER = 7500  -- Replace this with the actual rev limiter of your car

function update(dt)
    time_since_last_update = time_since_last_update + dt

    if time_since_last_update >= REFRESH then
        -- Update RPM only after the refresh interval has passed
        last_displayed_rpm = math.floor(car.rpm)
        time_since_last_update = 0
    end

    -- Determine the color based on RPM relative to the rev limiter
    local display_color = white
    if last_displayed_rpm >= 0.97 * REV_LIMITER then
        display_color = red
    end

    -- Display the RPM value with the determined color
    display.text({ text = last_displayed_rpm, pos = vec2(-40, 130), letter = vec2(100, 200), font = 'digital_big', color = display_color, alignment = 0.5, width = 555, spacing = 1 })
end
