Skip to content

Instantly share code, notes, and snippets.

@DragRedSim
Last active December 19, 2022 09:10
Show Gist options
  • Save DragRedSim/35b6895251f0e94193240e6df86df69c to your computer and use it in GitHub Desktop.
Save DragRedSim/35b6895251f0e94193240e6df86df69c to your computer and use it in GitHub Desktop.
Information on how to set up Arduino-powered lock lights in SimHub
OK, so you're looking to have your LEDs act as lock lights. The first
bit of warning I'll give you is that these are not always accurate to
the lights in the virtual car, as we don't always get the same
information used to calculate those lights. If you're OK with them not
always matching up, read on... This also assumes you're using discrete
LEDs; if you'd rather use a dashboard overlay or other displays, the
same principle applies to creating an output channel from ShakeIt, and
then calling it from another plugin. This is left as an exercise to the
reader (mainly because I don't use those functions).
The first thing you need to do is enable one of the ShakeIt plugins.
We're going to use that to calculate when the car is locked up. Go to
Settings, then Plugins, and make sure at least one of the ShakeIt
plugins is enabled. Either one will work fine for this. If you don't
need the other one, you can turn it off. If you're already running one
of them, you can use that; this doesn't necessarily require a separate
instance. Then head over to the ShakeIt plugin of choice's control
panel, and choose to "Add effect". Add a "Wheels lock" effect. Head to
that new effect, and under the Output label, there is an Export
sub-label. Under that, there are a couple of options. The one we want is
"Export output value as a property". Make sure that's checked, and a
"Property name" box will appear. Put something in there that you'll
remember; we'll need that code later. I use WheelsLock, and I'll use
that for the rest of this guide; if you use something else, wherever you
see WheelsLock, put in whatever you chose to put in here.
Now, let's head over to the "Effect Spatialization" panel. Under Mode,
pick the appropriate one - either Mono, for a single channel, which will
light up whenever anything is locked; Left/Right, which will give you
two channels, Front/Rear, which gives you a different two channels, or
Corners, which gives you four channels, one for each tyre. Then under
the Effect settings, we need to set a few things. These can all be tuned
to your personal preference; the values I give here are only
suggestions. First, the "Trigger when brake pedal reaches (%)" means
your LEDs won't turn on unless you are already on the brakes that
percentage. Generally, you'd want this as low as you can; the minimum is
1%. Below that, we have the Response filter section. By default, the
lock value given by SimHub ranges from 0 to 100. But often times, even
when you aren't locked up, this value is above zero, because of how
SimHub and ShakeIt calculate the value. So we want to alter these a bit.
The key thing here is the Threshold value; if ShakeIt calculates a value
below this number, it will report 0, and thus the LEDs will stay off. So
we want to set Threshold to a point where anything below it is fine, and
anything above it is when the wheels are locked. This isn't always
accurate to the game, because of how the calculations are made by
ShakeIt in comparison to the game. As a start, I'd try setting this to
20, and then fine-tune to your preference. If you're just wanting a
single LED per channel, that's all you need to tweak. If you want
multiple LEDs to act as somewhat of a graph, then continue to the next
paragraph. Otherwise, skip over it and rejoin afterwards.
To set up a graph-style set of LEDs, leave "Minimum force" at zero; this
will ensure that ShakeIt scales this range from the "Threshold" value to
100, to a 0-100 range. This means that the graph will not always light
up two or three LEDs whenever the calculated value is above the
Threshold. You can also alter the "Gamma Factor" and "Input Gain" to
change how this scaling occurs. A "Gamma Factor" above 1 will scale the
output from ShakeIt so that values increase faster, meaning more LEDs
will light up quicker; the inverse also holds true for "Gamma Factor"s
below 1. The "Input Gain" sets two things: if it's below 100, it will
set the maximum output value. If it's above 100, it will change the
point at which ShakeIt will output 100, and light up the entire group of
LEDs. Tweak these to your own personal preference. Note that both of
these values work in tandem; if you change one, it's likely to
necessitate a change in the other to compensate.
Now we need to set up the LEDs themselves. Head over to the Arduino
section, and pick "RGB LEDs" or "TM1638 LEDs" as appropriate. These
instructions will be for the newer, more modern LED configuration setup.
Pick out the LED(s) you want to use. Remember how earlier we set up a
Mode, which gave us one, two or four channels? This will have effects on
your configuration from here. If you want a single LED, add a "Custom
Formulas Status LED"; if you want multiple, use a "Custom Formulas
Gradient". Both are under "Custom formulas" in the "Add an effect"
dialog; you may need to scroll down. Either way, bring up the options of
your new effect. Under Behaviour, click Edit, and then "Computed value".
Then, click "Insert property", and in the filter box, type in the code
you put in the "Property name" earlier (for example, WheelsLock). It
will bring up one (if you picked Mono), two (Left/Right or Front/Rear)
or four (Corners) options. Pick the first one, and double-click to add
it. Then click OK. You've just assigned the value from ShakeIt to the
LED. Then modify the "Position" value to the appropriate LED ID to
start, according to how your LEDs are set up in real life. Set a colour
if you want too. Repeat this process (add an LED effect, assign a
separate channel) as appropriate. If you want to reverse the order of a
gradient, then select the "Right to left" option. If your options were
set up correctly in ShakeIt, gradients will automatically scale from
0-100, while single LEDs will read a 0 from ShakeIt as off, and anything
else as on.
Hopefully this will give you enough information to produce some lock
lights. A lot of this is just trial and error to tweak the effect, and
letting the LED just react to the changes there. I can't necessarily
reply to any requests for help beyond this guide, but hopefully this
will give you a good starting point. There is almost no chance of
breaking anything, so feel free to experiment!
@loukas371
Copy link

Thanks for this, it works! I wanted to set up a LED like this but I couldn't find a relevant property for dirt rally 2.0. The export from the ShakeIt motor worked fine and now I can add it to my dashboard.

@DragRedSim
Copy link
Author

Glad to hear it worked for you! I originally wrote this for iRacing usage, since it doesn’t export that as telemetry (ironically, because it can be used to create ABS systems in software for cars that don’t have them), but if it works for DR2.0, so much the better.

@loukas371
Copy link

It does work, just takes a bit of tuning like you said. And in a low grip game like this it is quite important as you can imagine. Though I dont plan to take it further than the LED I have added to my dashboard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment