Mike Shellim 26 June 2021
Updated 22 April 2022

Fading is a way of switching smoothly between two different configurations. OpenTX already offers fades - but only between flight modes. So this article shows how to create a fade within a flight mode.

## Example

As an example, we'll consider a motor which must operate in two modes, under the control of switch SF.

• When SF is up, the motor is controlled by the throttle stick.
• When SF is down, the motor has a fixed value of -85%.

The change from one state to the other must take 2 seconds, and must always be smooth.

## Implementation

The solution which follows is simple and robust, using one channel and four mixers.

The key is to make a channel act as a time-based ramp, controlled by SF. The ramp channel consists of a single mix:

• Source=SF.
• Weight=offset=50%
• Slow parameter = 1 second up/down.

CH10:Ramp
+= SF Weight(+50%) Offset(50%) Slow(u=1: d=1) -- fade duration

With SF in one position, the channel value is zero. With SF in the other position, the channel value is 100%. The transition takes 2 seconds. The ramp varies smoothly and predictably as the position of SF changes.

Next, we calculate the contribution of each end point according to where we are on the ramp, call this ramp%. One end point will contribute Ramp%, and the other (100% - Ramp%). Then we add the contributions, and assign the result to the motor channel. The equation is:

Motor = Thr*(100%-Ramp%) + (-85%)*Ramp%

Ramp% is the simply value of CH10, so we can implement the equation as follows:

CH2:Motor
+= Thr Weight(+100%) -- Thr ...
*= CH10:Ramp Weight(-100%) Offset(100%) -- ... *(100% — Ramp%)
+= CH10:Ramp Weight(-85%) -- -85%*Ramp%

Recall that the output of a mix = offset + source_value*weight. We make use of that in the second line to calculate  '(100% — Ramp%)'.

And that's it.

Here's a demo file: