GPS triangle race

Counting the laps: GPS triangle racing

Creating and using counters

Introduction to counters

Counters are useful in many situations - anything from counting laps, to playing tracks in a playlist. Implementing counters in Ethos does, however, require some advanced programming techniques, which we'll explore in this article. Let's get started!

Example 10-step counter

By way of an example, we'll create a 10-step counter, with auto and manual reset. Here's the full specification:

We'll use CH10 to store the counter value. Note that the counter increment is 5 (using a large increment avoids issues with internal rounding errors).

First, we set up two logical switches LSW1 and LSW2. LSW1 goes true if the counter has exceeded the maximum. LSW2 goes true if the counter has exceeded the limit, or if SJ is pressed:

LSW1: CH10 > 47


logical switches

Logical switches

Next, we create three free mixes to do the counting and reset.



FreeMix1: src=CH10, output=CH10

FreeMix2: src=special[0], offset=5%, active-condition=Edge(SI↓), output=CH10

FreeMix3: src=special[0], active-condition=LSW2, function=Replace, output=CH10


Free mix 1

Free mix 1. The single output is CH10 (not shown).

Free mix 2

Free mix 2

Free mix 3

Free mix 3

How it works

To understand how the mixers work, remember that Ethos executes a processing cycle several times a second. At the start of each cycle, all channels, including CH10, are reset to zero. Ethos then steps through the mixers one at a time, in the order they appear in the Mixers menu.

Considering our three mixers in isolation:

  1. FreeMix1 says "update CH10 with its value from the previous cycle", in other words, hold the last value. Without this mix, changes to CH10 in subsequent mixes would last only while those mixers were active.
  2. FreeMix2 is active when SI is pressed. While active, it increments the value of CH10 by 5. The 'edge' option ensures that the mix is active for one mixer cycle only.
  3. FreeMix3 is active when SJ is pressed, or when 10 steps have been counted (LSW2). It forces CH10 to zero (the Replace function means 'ignore all mixers above this one').


A 'decrement' function can be added, by inserting a mix immediately after FreeMix2.

FreeMix: src=special[0], offset=−5%, Active condition= edge(SH↓), output=CH10

The logical switches must be modified to detect negative values:

LSW1: not in range [-1 to 46]

LSW2: SJ↓ or LSW1

Example: manoeuvre callout system

Here's an example application, for aerobatic flyers. At the end of each manoeuvre, the pilot presses button SI, and the transmitter calls out the next manoeuvre.

We can use the counter code already defined above – all remains is to test the counter values, and to play the tracks.

Testing the counter

The counter can be tested using a bunch of logical switches:

LSW3: CH10 ~= 0

LSW4: CH10 ~= 5

LSW5: CH10 ~= 10


LSW12: CH10 ~= 45

Note the use of the ~= operator. This means 'approximately equal' and is necessary to avoid issues with internal rounding errors.

Playing the tracks

Finally, special functions are used to play the tracks, each triggered by a logical switch:

SF1: switch=LSW3 function=PlayTrack (track 1)

SF2: switch=LSW4 function=PlayTrack (track 2)


SF10: switch=LSW12 function=PlayTrack (track 10)


Topic on RC Groups