Hi All.
I have a script running currently that is very simple and turns my fans on and off sepeding on coolant temp.
What I want to do is run this script and Another which just filters my fuel level reading.
My problem is that when I try to run both scripts my fans stop working. its like the script is being ignored.
Here is the fan script and below that is what I was trying to run to allow both functions to work at the same time
function onTick()
if getAnalog(1) > 90
then
setGpio(0, 1)
else
setGpio(0, 0)
end
end
AND
function getCoolantTemp()
if getAnalog(1) > 90
then
setGpio(0, 1)
else
setGpio(0, 0)
end
end
function updateFuelAvg(value)
local i
if #fuelAvg == 0 then
--initialize averaging table
for i = 1, maxAvg do fuelAvg=0 end
end
fuelAvg[fuel2Index] = value
fuel2Index = fuel2Index + 1
if fuel2Index > maxAvg then fuel2Index = 1 end
local sum = 0
for i = 1, #fuelAvg do
sum = sum + fuelAvg
end
setChannel(fuel2Id, sum / maxAvg)
end
setTickRate(30)
function onTick()
getcoolantTemp()
updateFuelAvg(getAnalog(0))
end
Any help would be greatly appreciated
Im going insane. Help required geeting 2 scripts to work
Im going insane. Help required geeting 2 scripts to work
Last edited by Taner on Tue Sep 26, 2017 5:56 pm, edited 1 time in total.
Is your fuel average function working? Where did you set the maxAvg value? And where did you initialize the fuel2Index variable?
Your idea is to smooth the fuel reading, is it right? You can try this setting as well:
viewtopic.php?p=25368&highlight=alpha#25368
Your idea is to smooth the fuel reading, is it right? You can try this setting as well:
viewtopic.php?p=25368&highlight=alpha#25368
The problem is almost certainly two onTick functions. Get rid of the top onTick function
The onTick method is what the Lua engine executes every N (the value of setTick) milliseconds. Defining it twice will cause problems. Copy and paste the entire script that isn't working, and only that script so we can actually see what you have.[/code]
Code: Select all
function onTick()
getcoolantTemp()
updateFuelAvg(getAnalog(0))
end
I think this is the answer as well. You should define each function separately and call all of your functions in the single onTick function. I believe onTick is what executes all of your custom scripts.gizmodo wrote:The problem is almost certainly two onTick functions. Get rid of the top onTick functionThe onTick method is what the Lua engine executes every N (the value of setTick) milliseconds. Defining it twice will cause problems. Copy and paste the entire script that isn't working, and only that script so we can actually see what you have.[/code]Code: Select all
function onTick() getcoolantTemp() updateFuelAvg(getAnalog(0)) end