# Smooth fades

## Introduction

*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.

- 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 mode 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.

Start by making a time-based ramp channel, controlled by SF. Where we are on the ramp determines the proportion of each behaviour.

CH10:Ramp

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

With SF up, the channel value settles to 0%. With SF down, the channel value settles to 100%. The transition takes 2 seconds. The use of 'slow' ensures that the ramp always varies smoothly and predictably as SF is toggled.

Next, we calculate the contribution of each end point according to where we are on the 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: