MSFS2020 How to Create a Blinking LED configuration - MobiFlight/MobiFlight-Connector GitHub Wiki

[!NOTE]
MobiFlight versions 10 and above contain built-in support for blink modifier for outputs

How to Create a Blinking LED Using Mobiflight and WASM Module

In this tutorial we will keep things simple by just configuring a LED that blinks with the Parking Brake status, nothing else. This procedure assumes you already have a working installation of Mobiflight, the wasm module and at least one LED connected to your board and configured in Mobiflight Modules.

Two Output Config Method

  1. Create an output config that will use the simulator time variable. Enter this variable name in the Variable field of the output config window.

(E:SIMULATION TIME, second)

This variable displays the time in seconds elapsed since the simulator started.

  1. Add some integer math to this variable by applying the modulo function with 2 as divider.

(E:SIMULATION TIME, second) flr 2 %

This simple statement will now display an alternating value of 0 and 1 each second. You can name this config as "Blink 1 second". You could configure a LED to display with this output, but it would not be very useful, as the LED will blink forever. So, we next add a variable to control when to blink.

image

  1. Create an output config for the variable you wish to display with the blinking LED. For example, the classic Parking Brake variable used in the Mobiflight video tutorial, but it can be any other variable:

(A:BRAKE PARKING INDICATOR,Bool)

image

  1. Configure the Display tab to use a LED in your board. This part is identical to the LED for parking brake tutorial. With this, You should now have a LED that turns on and off with the Parking Brake indicator.

  2. We will now add the blink function by using the Transform field and bring in the “Blink 1 second” config as a config reference. Go to Config References and put a checkmark on the first config ref. Select from the list of configs “Blink 1 second”. Now use the placeholder for that config ref, which in this case is the “#” sign and put the formula $*# in the Transform field. Both variables in this formula only take a value of either 0 or 1, so multiplying the two together results also in a value of 0 (if either variable is equal to 0) or 1 (only when both variables are equal to 1).

image

  1. Save your MF config. Your LED will now blink once per second when the Parking Brake is On.

This method has the convenience that the blink output configuration is separate from the variable that actually blinks, so the blink config can be used in multiple other blinking outputs, if so desired.

Alternate Method Using One Output Configuration

The same effect can be achieved with only one output configuration by moving the two variables and all the math to the output configuration Variable field. The syntax is the same as any other WASM module event script, except there is no event name. The same math operations described earlier are condensed into one expression with the following statement:

(A:BRAKE PARKING INDICATOR,Bool) (E:SIMULATION TIME, second) 2 % *

image

Possible Variations For Other Use Cases

This type of technique can be used, with some modifications in the preconditions and formulas, in other instances like blinking values in an LCD screen, or implementing a three state LED indicator (OFF-ON-BLINK).

The frequency of the blink can also be adjusted by changing the formula used in the blink. For example, you can increase the frequency to twice per second by multiplying the E: variable times 2.

(E:SIMULATION TIME, second) 2 * 2 %

Conversely, you can reduce the frequency to once every 5 seconds by diving the variable by 5.

(E:SIMULATION TIME, second) 5 / 2 %

We have seen in all of these examples a binary count. But this count can be changed for other applications by modifying the divider in the modulo operation (%). So for example a count from 0 to 5, every second, is just as easily programmed with:

(E:SIMULATION TIME, second) 6 %

or for every two seconds:

(E:SIMULATION TIME, second) 2 / 6 %