Page 1 of 1
How to blink a light on the GPIO?
Posted: Thu Jan 29, 2015 2:06 am
by jakekooser
I have a light on my dash that I want to use to indicate when my RCP is armed, like for the autocross script. I would like to have it blink to indicate that the RCP is ready and then after the script gives the 'startLogging()' command, have it turn on solid until logging stops.
Right now it is connected to one of the GPIO ports, with the jumper and software set to output, and it just stays on constantly.
I still don't have the script in the box, nor the 'arm' switch hooked up, but will do that tomorrow.
Can someone help me get pointed in the right direction?
Posted: Mon Feb 09, 2015 5:28 pm
by brentp
Hi Jake,
We can help with that. Can you expand on your requirements? What does it mean to be 'armed' - does it mean if the unit is simply powered up?
Generally to toggle the output (flash the LED) it would involve alternating the output state of the unit on every tick. like this:
Code: Select all
setTickRate(10) -- 10 Hz
ledState = 0
function onTick()
setGpio(0, ledState)
if ledState == 0 then ledState = 1 else ledState = 0 end
end
Make sure in your GPIO config you have the GPIO channel mode (in this case, the first one) set to "output"
http://autosportlabs.net/RaceCapturePro ... _state_.29
Posted: Tue Feb 10, 2015 12:15 am
by jakekooser
Brent,
when I write 'armed' I was referring to the 'AutoX' script in the examples:
Automatically start Logging upon Launch (AutoX / Rally / Hill Climb)
This script will start Logging when a dash mounted "ARM" switch is activated via an input and G-force exceeds a threshold Given:
GPIO 0 configured as input and connected to dash mounted "Arm" switch
Default RaceCapture/Pro mounting orientation (terminal block facing forward, mounted upright)
G-force launch threshold is -0.1 G
flipping the ARM switch to 'Off' will stop logging
setTickRate(30)
function onTick()
local arm = getGpio(0)
local g = getAccel(1)
if arm == 0 then
stopLogging()
end
if arm == 1 and g < 0.1 then
startLogging()
end
end
I have a dpdt switch that I want to use to select either 'autocross' or 'normal' modes for autoX and track, respectively. I posted a separate question about how to do that.
I would like to select, for example, the AutoX mode, have the RCP start logging upon launch as that script does, and to have it blink the LED on the dash once logging is started. To my non-programmer mind, it seems as simple as maybe calling a function, just like one does to start logging, but the LUA scripting is a bit confusing to me right now.
How would one handle this?
Posted: Wed Feb 11, 2015 7:56 pm
by brentp
Here's an improved example of the launch script that flashes an external LED when logging. Note, I wrote this blind (without direct testing), but should work.
Use the logging window to check for problems once you upload and run the script.
Code: Select all
--GPIO 0 is configured for input (connects to switch)
--GPIO 1 is configured for output (connects to LED)
--IMU channel 1 mapped to Fore/aft accelerometer channel
gForceThreshold = 0.25 -- launch threshold in G force
imuChannel = 1 --IMU channel 1 mapped to Fore/aft accelerometer channel
setTickRate(30) --onTick() is called 30 times/sec
ledState = 0
function toggleLed()
setGpio(1, ledState)
if ledState == 0 then ledState = 1 else ledState = 0 end
end
function onTick()
local arm = getGpio(0)
local g = getAccel(imuChannel)
if arm == 0 then
stopLogging()
end
if arm == 1 and g > gForceThreshold then
startLogging()
toggleLed()
end
end