RegisterSearchFAQMemberlistUsergroupsLog in
Reply to topic Page 1 of 1
How to blink a light on the GPIO?
Author Message
Reply with quote
Post How to blink a light on the GPIO? 
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?

View user's profile Send private message Visit poster's website
Reply with quote
Post  
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:

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_Lua_Scripting#setGpio_.28_channel.2C_state_.29


_________________
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter
View user's profile Send private message Send e-mail
Reply with quote
Post  
Brent,

when I write 'armed' I was referring to the 'AutoX' script in the examples:
Quote:
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?

View user's profile Send private message Visit poster's website
Reply with quote
Post  
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. Smile

Use the logging window to check for problems once you upload and run the script.

Code:
--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


View user's profile Send private message Send e-mail
Display posts from previous:
Reply to topic Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum