Multiplexed ShiftX lights
Posted: Fri Apr 03, 2015 6:35 pm
This weekend I've been testing a script which multiplexes the ShiftX so that it operates as both shift lights and an error light.
If there's an error condition (temperature too high or oil pressure too low), only the central red light is illuminated. If there's no error condition, it operates as shift lights.
Here's the script:
If there's an error condition (temperature too high or oil pressure too low), only the central red light is illuminated. If there's no error condition, it operates as shift lights.
Here's the script:
Code: Select all
FREQUENCY_HZ = 10
RPM_THRESHOLDS = {12000, 12300, 12500}
MAX_OIL_TEMP = 100
MAX_WATER_TEMP = 100
MIN_OIL_PRESSURE_LOW_REVS = 5
MIN_OIL_PRESSURE_HIGH_REVS = 10
LOW_REVS = 3000
setTickRate(FREQUENCY_HZ)
function lightOn(light, on)
if on then
setPwmDutyCycle(light, 0)
else
setPwmDutyCycle(light, 100)
end
end
function updateShiftLights()
local rpm = getTimerRpm(0)
lightOn(0, rpm > RPM_THRESHOLDS[1])
lightOn(1, rpm > RPM_THRESHOLDS[2])
lightOn(2, rpm > RPM_THRESHOLDS[3])
end
function oilTempError()
return getAnalog(0) > MAX_OIL_TEMP
end
function waterTempError()
return getAnalog(1) > MAX_WATER_TEMP
end
function oilPressureError()
local oilp = getAnalog(2)
if getTimerRpm(0) < LOW_REVS then
return oilp < MIN_OIL_PRESSURE_LOW_REVS
else
return oilp < MIN_OIL_PRESSURE_HIGH_REVS
end
end
function errorCondition()
return oilTempError() or waterTempError() or oilPressureError()
end
function displayError()
lightOn(0, false)
lightOn(1, false)
lightOn(2, true)
end
function onTick()
if getGpsSpeed() > 10 then
startLogging()
end
if errorCondition() then
displayError()
else
updateShiftLights()
end
end