MSFS2020 Configuring an External Chronometer in Mobiflight - MobiFlight/MobiFlight-Connector GitHub Wiki

The purpose of this tutorial is to show how to configure a virtual Chronometer for your Mobiflight panel. This virtual device will be independent of the virtual cockpit in MSFS2020, but with minor additions, could be made to synchronize with the sim. However, we will not cover how to do in this document. We will only focus on the chronometer function: starting, stopping and resetting the timer and displaying minutes and seconds in a 7-segment module.

We will take as model for the behavior of our chronometer the unit found in the FBW A320 aircraft. The chronometer in this airplane has only two buttons: one for Start/Stop and one for Reset. The Reset button restarts the time count if the timer is running or will turn off the display if the timer is not running (Stop mode). The display is of minutes and seconds in a four-digit display.

image

Hardware side

You will need the following parts to build this chronometer:

1 Mobiflight compatible Arduino board (Mega, Uno, or Pro Micro)
2 button switches
1 8-digit 7-segment max7219 module (only four digits are required)
wiring as required

We assume you are familiar with how to wire the hardware. If not, there are other tutorials that cover these details. Buttons have two legs, one goes to an Arduino pin, the other leg goes to ground. The 7-segment displays have five pins: VCC goes to the Arduino 5v pin, GND goes to ground, DIN, CS, and CLK go to Arduino pins. Make a note of which pins you have used to connect buttons and display module. Any pins can be used. The only exception being that pin 13 on a Mega or Uno board should not be used for an input device because it has the builtin LED connected there.

Configure the Mobiflight hardware specifying the pins used to connect your hardware. You will create one hardware config for each button and another config for the LED module. Test that your newly connected and configured hardware is detected by Mobiflight by activating the logging mode in Settings and verifying that the log registers when you push the buttons.

Mobiflight Configuration

Now create one input config for the Start/Stop chronometer button and map it to the first hardware button.
Create another input config for the Reset button and map it to the second hardware button.

Start/Stop Button input

In the Input tab, select the Arduino board and the first hardware button config you created previously. In the On Press tab, select Action type is Microsoft Flight Simulator 2020. You don't need to select any presets, as we will be using custom code in this project. Check the Show Preset Code box and copy the code below to the code box.

image

On Press tab

(L:myChrRun) ! s0 (>L:myChrRun) (L:myChrTime) -1 == if{ 0 (>L:myChrTime) }
   l0 if{ (E:SIMULATION TIME, second) 1 + (>L:myChrStart) }
   els{ 0 (>L:myChrStart) }
### Here goes the specific aircraft chrono start/stop event ###
### In the case of FBW A320 it is (>H:A32NX_CHRONO_TOGGLE)  ###

Notes on the code:

  • myChrRun is flag that is toggled with each press of the button to signal that the chronometer is running.
  • If the chronometer has just started myChrTime is equal to -1. If so, this variable is set to 0.
  • myChrStart is a timer tick of 1 second that stores the time for the next chronometer time update.
  • If the chronometer has been stopped, myChrStart is set to 0.
  • Optional, include the specific aircraft chrono toggle event to sync with the virtual cockpit

Reset Button Input

Repeat the same procedure above for the other button configuration.

image

On Press tab

(L:myChrRun) if{ 0 (>L:myChrTime) (E:SIMULATION TIME, second) 1 + (>L:myChrStart) } 
els{ -1 (>L:myChrTime) } } 
### Here goes the specific aircraft chrono Reset event  ###
### In the case of FBW A320 it is (>H:A32NX_CHRONO_RST) ###

Notes on the code:

  • If the chronometer is running (myChrRun is equal to 1, then the running reset is made, only myChrTime is set to 0.
  • If the chronometer is not running, myChrTime is set to -1 to signal that the display should be blank.
  • Optional, include the specific aircraft chrono reset event to sync with the virtual cockpit

7-Segment Output Display

Create an output config in Mobiflight for the 7-segment display as shown below. Do not select any preset, as we will be running custom code with this project.

image

(L:myChrRun) if{ (E:SIMULATION TIME, second) (L:myChrStart) > if{ 
   (L:myChrTime) 1 + (>L:myChrTime) 
   (L:myChrStart) 1 + (>L:myChrStart) } }
(L:myChrTime)

Notes on the code:

  • myChrRun is monitored constantly to detect whether the chronometer is running or not.
  • If true, then check if it is time for the 1 second update. If not, nothing is done.
  • If it is time for an update, myChrTime (the elapsed time value) is incremented by 1.
  • The next update time is setup in myChrStart.
  • The output value is always set to myChrStart for display.

Transform

if($=-1,'    ',Floor($/60%60)*100+$%60)
  • The transform formula checks for a value of -1 to blank the display if true.
  • If not equal to -1, then the elapsed time in seconds is parsed into minutes and seconds for the display.

The End.