RegisterSearchFAQMemberlistUsergroupsLog in
Reply to topic Page 1 of 1
Making Shift lights flash on shiftx
Author Message
Reply with quote
Post Making Shift lights flash on shiftx 
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

View user's profile Send private message
Reply with quote
Post  
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:

--[[
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]


_________________
Andrew Stiegmann (Stieg)
Principal Engineer
Autosport Labs Inc.
View user's profile Send private message Send e-mail Visit poster's website
Reply with quote
Post  
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

View user's profile Send private message
Reply with quote
Post  
Could I ad in a line

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

View user's profile Send private message
Reply with quote
Post  
Code:
If rpm > 7400 toggle Gpio (2,1) (1,1) (0,1) 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.


_________________
Andrew Stiegmann (Stieg)
Principal Engineer
Autosport Labs Inc.
View user's profile Send private message Send e-mail Visit poster's website
Reply with quote
Post  
What is meant by 3 calls I am a complete novice

View user's profile Send private message
Reply with quote
Post  
Quote:
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.


_________________
Andrew Stiegmann (Stieg)
Principal Engineer
Autosport Labs Inc.
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:
Reply to topic Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum