Page 1 of 1

Making Shift lights flash on shiftx

Posted: Wed Apr 27, 2016 7:30 am
by Ash-b-84
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

Posted: Wed Apr 27, 2016 2:21 pm
by stieg
Here is a script I wrote a while back. It uses the 3 PWM outputs on the RCP unit to control the lights instead of the GPIO units. You will need to adjust your RPM values accordingly.

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&#40;0&#41;
        lightOff&#40;1&#41;
        lightOff&#40;2&#41;
   elseif 3000 < rpm and rpm < 4500 then
	lightOn&#40;0&#41;
        lightOff&#40;1&#41;
        lightOff&#40;2&#41;
   elseif 4500 < rpm and rpm < 5000 then
        lightOn&#40;0&#41;
        lightOn&#40;1&#41;
        lightOff&#40;2&#41;
   elseif 5000 < rpm and rpm < 5500 then
        lightOn&#40;0&#41;
        lightOn&#40;1&#41;
        lightOn&#40;2&#41;
   else
        toggleLight&#40;0&#41;
        toggleLight&#40;1&#41;
        toggleLight&#40;2&#41;
   end
end


function controlLights&#40;&#41;
   checkRpm&#40;&#41;
   updateLights&#40;&#41;
end

-- Start!

function onTick&#40;&#41;
   controlLights&#40;&#41;
end
[/code]

Posted: Thu Apr 28, 2016 2:09 am
by Ash-b-84
I use the gpio so my current one looks like this

Code:

setTickRate(15) --15Hz

--Shift Now!!!!
function onTick()
rpm=getTimerRpm(2) --read RPM

--activate LEDs
if rpm > 8000 then return end --this filters out RPM spikes
if rpm > 6600 then setGpio(2,1) else setGpio(2,0) end
if rpm > 7000 then setGpio(1,1) else setGpio(1,0) end
if rpm > 7400 then setGpio(0,1) else setGpio(0,0) end
end

Posted: Thu Apr 28, 2016 2:17 am
by Ash-b-84
Could I ad in a line

If rpm > 7400 toggle Gpio (2,1) (1,1) (0,1) end

Posted: Thu Apr 28, 2016 11:56 am
by stieg

Code: Select all

If rpm > 7400 toggle Gpio &#40;2,1&#41; &#40;1,1&#41; &#40;0,1&#41; end
I don't believe that is valid Lua. If you broke it up into 3 calls, then yes. Feel free to use this script.

Posted: Fri Apr 29, 2016 11:21 am
by Ash-b-84
What is meant by 3 calls I am a complete novice

Posted: Fri Apr 29, 2016 2:21 pm
by stieg
What is meant by 3 calls I am a complete novice
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.