Here is my script to run this on the Digital I/O (GPIO) pins
Code: Select all
--Pin assignments--
--RPM is pin 20 / PulseIn 1
--First light is pin 17 / GPIO1 10Hz Output / #2 on shift light - green
--Second light is pin 16 / GPIO2 10Hz Output / #1 on shift light - yellow
--Third light is pin 15 / GPIO3 10Hz Output / #3 on shift light - red
-- CONSTANTS --
FREQ_HZ = 25 --1000*1/FREQ_HZ=loop time in ms. e.g. 25Hz=40ms--
loop_time = 1000 * 1 / FREQ_HZ
MAX_BLINK_PERIOD = 1000 --in ms (1s or 1000ms is reasonable value)--
MAX_ON_TIME = 500 --in ms (0.5s or 500ms, half off/on is reasonable value--
testRPM = 3000 --test interface for use on bench--
LL1 = 1000 --light 1 lower threshold to start blinking--
UL1 = 1500 --light 1 upper threshold above which goes solid--
LL2 = 1500 --light 2 lower threshold to start blinking--
UL2 = 2000 --light 2 upper threshold above which goes solid--
LL3 = 2000 --light 3 lower threshold to start blinking--
UL3 = 2500 --light 3 upper threshold above which goes solid--
-- FUNCTIONS --
function ctON(ul,ll)
--RPM=getTimerRpm(0)
RPM=testRPM
factor = 0.5 * FREQ_HZ * (1 - (ul - RPM) / (ul - ll))
if factor >= 0.5 * FREQ_HZ then --can't blink faster than tickRate/2--
on_time = MAX_ON_TIME
elseif factor < 1 then --can't blink slower than max period--
on_time = 0
else
on_time = MAX_ON_TIME / factor
end
return on_time / loop_time
end
function ctMAX(ul,ll)
--RPM=getTimerRpm(0)
RPM=testRPM
factor = 0.5 * FREQ_HZ * (1 - (ul - RPM) / (ul - ll))
blink_period = MAX_BLINK_PERIOD / factor
return blink_period / loop_time
end
-- Ini --
setTickRate(FREQ_HZ)
j = 0
k = 0
l = 0
-- RUN --
function onTick()
--start light 1 section--
if j < ctON(UL1,LL1) then
setGpio(0,0)
else
setGpio(0,1)
end
if j < ctMAX(UL1,LL1) then
j = j + 1
else
j = 0
end
--end light 1 section--
--start light 2 section--
if k < ctON(UL2,LL2) then
setGpio(1,0)
else
setGpio(1,1)
end
if k < ctMAX(UL2,LL2) then
k = k + 1
else
k = 0
end
--end light 2 section--
--start light 3 section--
if l < ctON(UL3,LL3) then
setGpio(2,0)
else
setGpio(2,1)
end
if l < ctMAX(UL3,LL3) then
l = l + 1
else
l = 0
end
--end light 3 section--
end
Code: Select all
--Pin assignments--
--RPM is pin 20 / PulseIn 1
--set the jumpers to ON
--First light is pin 6 / Vout1 10Hz 100 100 0.1 / #2 on shift light - green
--Second light is pin 5 / Vout2 10Hz 100 100 0.1 / #1 on shift light - yellow
--Third light is pin 4 / Vout3 10Hz 100 100 0.1 / #3 on shift light - red
-- CONSTANTS --
FREQ_HZ = 25 --1000*1/FREQ_HZ=loop time in ms. e.g. 25Hz=40ms--
loop_time = 1000 * 1 / FREQ_HZ
MAX_BLINK_PERIOD = 1000 --in ms (1s or 1000ms is reasonable value)--
MAX_ON_TIME = 500 --in ms (0.5s or 500ms, half off/on is reasonable value--
testRPM = 3000 --test interface for use on bench--
LL1 = 1000 --light 1 lower threshold to start blinking--
UL1 = 1500 --light 1 upper threshold above which goes solid--
LL2 = 1500 --light 2 lower threshold to start blinking--
UL2 = 2000 --light 2 upper threshold above which goes solid--
LL3 = 2000 --light 3 lower threshold to start blinking--
UL3 = 2500 --light 3 upper threshold above which goes solid--
-- FUNCTIONS --
function ctON(ul,ll)
--RPM=getTimerRpm(0)
RPM=testRPM
factor = 0.5 * FREQ_HZ * (1 - (ul - RPM) / (ul - ll))
if factor >= 0.5 * FREQ_HZ then --can't blink faster than tickRate/2--
on_time = MAX_ON_TIME
elseif factor < 1 then --can't blink slower than max period--
on_time = 0
else
on_time = MAX_ON_TIME / factor
end
return on_time / loop_time
end
function ctMAX(ul,ll)
--RPM=getTimerRpm(0)
RPM=testRPM
factor = 0.5 * FREQ_HZ * (1 - (ul - RPM) / (ul - ll))
blink_period = MAX_BLINK_PERIOD / factor
return blink_period / loop_time
end
-- Ini --
setTickRate(FREQ_HZ)
j = 0
k = 0
l = 0
-- RUN --
function onTick()
--start light 1 section--
if j < ctON(UL1,LL1) then
setAnalogOut(0,0)
else
setAnalogOut(0,10) --with value of 5 measured 2.2V and dim light so set to 10, measured 4.75V
end
if j < ctMAX(UL1,LL1) then
j = j + 1
else
j = 0
end
--end light 1 section--
--start light 2 section--
if k < ctON(UL2,LL2) then
setAnalogOut(1,0)
else
setAnalogOut(1,10) --with value of 5 measured 2.2V and dim light so set to 10, measured 4.75V
end
if k < ctMAX(UL2,LL2) then
k = k + 1
else
k = 0
end
--end light 2 section--
--start light 3 section--
if l < ctON(UL3,LL3) then
setAnalogOut(2,0)
else
setAnalogOut(2,10) --with value of 5 measured 2.2V and dim light so set to 10, measured 4.75V
end
if l < ctMAX(UL3,LL3) then
l = l + 1
else
l = 0
end
--end light 3 section--
end
Now I'm not a software engineer, calibration is my thing, but I know enough to dabble and be dangerous So improvement suggestions are welcome because I'm sure I didn't follow the best coding practices.....
Oh, and this is running with RaceAnalyzer V1.1.15 on MK1 hardware running firmware 1.2.7. (A little hesitant to jump on the V2 release since it is so new and everything works now as I need it.)