Page 1 of 1

Flashing Warning Light

Posted: Mon Sep 18, 2017 4:17 pm
by ross2004
Preface: noob here when it comes to scripting.

I've seen the wiki example script for a warning light for say temperature, low pressure, etc.- is it possible to have this light flash, and what would that code look like? Thanks!

Standard:

--Analog 0 is engine temp, in degrees F
--Analog 1 is oil pressure, in PSI

function onTick()
if getAnalog(0) > 212 or getAnalog(1) < 10 then
setGpio(0, 1)
else
setGpio(0, 0)
end
end

Posted: Wed Oct 04, 2017 5:42 pm
by brentp
Hi, you'd have to have a separate counter that increments on every onTick(). A simple way is, if that value is odd, then make sure the output is off.

There are some shift light examples in our example library that implement something like this.

Let us know what you come up with!

Posted: Sat Apr 21, 2018 9:48 pm
by PS14
Here's a script to make a light wired to GPIO(0) come on at a certain point and flash at a different point (like water temp). thanks to David Alexander.

--point at which light comes on
local waterOn = 195
--point at which light flashes
local waterBlink = 200

local timer = 1

function warningLed()
if getAnalog(0) > waterOn then
setGpio(1, 1)
else
setGpio(1, 0)
end
if getAnalog(0) > waterBlink then
if timer == 1 then
setGpio(1, 0)
timer = 2
else timer = 1
end
end
end

function onTick()
warningLed()
end

Posted: Wed May 09, 2018 6:17 pm
by ross2004
Nice, I'm going to try and implement that this weekend. I like the simple "on" along with "flashing" combo.

Posted: Wed May 09, 2018 7:03 pm
by PS14
Just a thought. I've always used a redundant water pressure sender to a lite, completely independent of the digital gauges/sender. in dirt racing we are usually blowing hoses or poking holes in the radiator so you'll see a loss of pressure long before any rise in temp. sometimes you wont even see a rise in temp since a typical water temp gauge cant measure air temp (i.e no water in block). just food for thought.