Shift X shift light

Discussion on the Lua Scripting capabilities for RaceCapture/Pro. Also see the <a href="http://autosportlabs.net/RaceCapturePro_Lua_Scripting">Lua Scripting Guide</a>

Moderators: JeffC, stieg

Post Reply
drivesport
Posts: 3
Joined: Sun May 27, 2018 7:28 pm

Shift X shift light

Post by drivesport »

Hello,

I am scripting first timer so please bare with me. We are trying to hook up the shift x light which uses three GPIO pins but we have had no success using the script provided in the example:

------
setTickRate(15)

function onTick()
local r = getTimerRpm(0)
if r > 5000 then setGpio(2,1) else setGpio(2,0) end
if r > 6000 then setGpio(1,1) else setGpio(1,0) end
if r > 7000 then setGpio(0,1) else setGpio(0,0) end
end
-------
We are using CAN bus off the megasquirt for all values, including RPM. Would this change the script?
FYI: the lights flash x1 when the ignition is turned on so we can confirm there is power going to the lights.

Thank you for the help.

PK

drivesport
Posts: 3
Joined: Sun May 27, 2018 7:28 pm

Post by drivesport »

Anyone? Maybe I have posted in the wrong sub-forum.

Cheers,
PK

MikeD
Posts: 39
Joined: Sun May 29, 2016 11:55 am
Location: Austria
Contact:

Post by MikeD »

The function getTimerRpm(0) is your problem. This function would provide an RPM signal from a hardwired sensor connected to FrequencyIn 1.

You would need to get the value from your CAN mapped RPM channel into the lua scripting section.
For the following to work you may need FW 2.13.x to be able to use the command getChannel("xxxChannelNamexxx") and get the value from the matching channel name into the lua scritping section.

Try the following and please give some feedback how it works for you:

------
setTickRate(25)

function onTick()
local r = getChannel("RPM") --assuming RPM is the name you have choosen
if r ~= nil then
if r > 5000 then setGpio(2,1) else setGpio(2,0) end
if r > 6000 then setGpio(1,1) else setGpio(1,0) end
if r > 7000 then setGpio(0,1) else setGpio(0,0) end
end
end
-------

Regards,
Mike

tfriest
Posts: 32
Joined: Wed Nov 27, 2013 4:00 am

Post by tfriest »

I wrote a test script to make sure I had hooked my leds up right...

greenLed = 0
yellowLed = 1
redLed = 2

tick = 0
function onTick()
--println(tick)
if tick == 0 then
setGpio(greenLed,1)
elseif tick == 1 then
setGpio(yellowLed, 1)
elseif tick == 2 then
setGpio(redLed, 1)
else
tick = -1
setGpio(greenLed, 0)
setGpio(yellowLed, 0)
setGpio(redLed, 0)
end

tick = tick + 1
end

You can just plug a laptop into the usb port and run that script.

Post Reply