Making Shift lights flash on shiftx
Posted: Wed Apr 27, 2016 7:30 am
How to make all shift lights flash on my shift x or when max rpm is reached if somone could supply a script I can add into my existing one that would be great
Code: Select all
--[[
Inputs as wired on 2014-12-05 -- Stieg
Input
Timer 0 - RPM
Tach Lights
0 - Green Light
1 - Yellow Light
2 - Red Light
]]
-- Globals --
LIGHTS = 3
LIGHT_VALS = {}
FREQUENCY_HZ = 25
-- Global Init --
setTickRate(FREQUENCY_HZ)
function toggleLight(index)
LIGHT_VALS[index] = not LIGHT_VALS[index]
end
function lightOn(index)
LIGHT_VALS[index] = true
end
function lightOff(index)
LIGHT_VALS[index] = false
end
local lCount = 0
repeat
lightOff(lCount)
lCount = lCount + 1
until lCount >= LIGHTS
-- Script --
function updateLights()
local l = 0
repeat
-- Convert our booleans to 1 (true) or 0 (false) --
local val = LIGHT_VALS[l]
local dc = 0
if not val then
dc = 100
end
setPwmDutyCycle(l, dc)
l = l + 1
until l >= LIGHTS
end
function checkRpm()
local rpm = getTimerRpm(0)
if rpm < 3000 then
lightOff(0)
lightOff(1)
lightOff(2)
elseif 3000 < rpm and rpm < 4500 then
lightOn(0)
lightOff(1)
lightOff(2)
elseif 4500 < rpm and rpm < 5000 then
lightOn(0)
lightOn(1)
lightOff(2)
elseif 5000 < rpm and rpm < 5500 then
lightOn(0)
lightOn(1)
lightOn(2)
else
toggleLight(0)
toggleLight(1)
toggleLight(2)
end
end
function controlLights()
checkRpm()
updateLights()
end
-- Start!
function onTick()
controlLights()
end
Code: Select all
If rpm > 7400 toggle Gpio (2,1) (1,1) (0,1) end
If you intend to edit the scripts then it would be wise to jump into Lua a bit first to get an idea of what is happening. Here is a free tutorial provided by the folks who wrote LUA: https://www.lua.org/pil/contents.html#1. I would suggest you merely adjust the numbers in the checkRpm function in the script provided rather than try to add to it. Trying to jump straight in and do larger edits without experience will lead to lots of frustration, and that is no fun.What is meant by 3 calls I am a complete novice