Controlling the brightness of LEDs and 7 segment modules - MobiFlight/MobiFlight-Connector GitHub Wiki

THIS IS WORK IN PROGRESS

The brightness of LEDs and 7-segment modules can be controlled inside Mobiflight. In this tutorial we will cover how to do this. However, we will not get into any details about wiring potentiometer, encoders, LEDs or 7-segment modules, as those topics are covered in other tutorials. It is assumed all hardware has been properly connected and tested.

The Basic Technique

A potentiometer or encoder can be used to set the value of either a Mobiflight Variable or a simulator Lvar in MSFS2020, or maybe a dataref in Xplane12. In many cases this value ranges from 0 to 100, which we will use as example in this tutorial. It can really be set to any arbitrary range. This value is then used to represent the brightness level for either LEDs or 7-segment displays. This value can also be used to synchronize the lights brightness in the simulator and your hardware panel.

In the case of LEDs, they need to each be connected to a PWM (Pulse Width Modulation) capable Arduino pin. This PWM signal can vary from 0 (off) to 255 (full bright). Mobiflight can control the PWM function available from some of the Arduino board pins. Please refer to your specific board pinout diagram to determine which pins have this capability. In a Uno board, for example, PWM capable pins are: 3, 5, 6, 9, 10 and 11.

High-Res-Arduino-UNO-Pinout

For Max7219 7-segment modules, there is an onboard register that Mobiflight uses to control the brightness of the LEDs, that can vary from 0 (off) to 15 (full bright).

Mobiflight Input Configuration

Potentiometer

A typical Mobiflight analog input config for a MF variable might be this simple formula in the value field to set the value in the range 0-100:

@/10.23

image

Bear in mind this can be an Lvar or Dataref just as well.

Encoder

In the case of an encoder, a typical input config formula for a MF variable would look like this for Left and Right. The result will again be a value in the range 0 to 100.

Left turn: Max($-5,0)

image

Right turn: Min($+5,100)

image

Note the use of the Min and Max functions to limit the upper and lower bounds (0-100).

Mobiflight Output Configuration

We showed how the input with either a potentiometer or encoder can be modeled into a value range 0 to 100. This is a typical range used in the simulator for controlling panel and other lights brightness.

LEDs