Taranis: A Volume Control That Doesn't Take Up Any Pots or Switches - RC Groups
Thread Tools
This thread is privately moderated by Miami Mike, who may elect to delete unwanted replies.
Mar 26, 2017, 12:25 PM
Registered Taranis User
Miami Mike's Avatar
Mini-HowTo

Taranis: A Volume Control That Doesn't Take Up Any Pots or Switches


Taranis: A Volume Control That Doesn't Take Up Any Pots or Switches
for OpenTX version 2.1.9

Like my other scripts so far, volume.lua is implemented like a telemetry script but doesn't actually provide telemetry. (But in this case it could with modification.) What it does is provide a way to adjust volume and store the setting without using any of the switches, knobs, or sliders that are otherwise used to control your model. Instead, the buttons next to the display are used.

The script needs one global variable ("GV"), which you can name "Volume." It can be any one of the nine global variables in each of your model memories and can even be a different GV for each model, although that would require multiple copies of volume.lua with minor changes to each copy and different filenames. I'm using GV1 in my radio and in the examples that follow.

There are installation instructions embedded in the script but I'll post more detailed instructions here.
  • Download volume.txt from the link below, edit it as needed, rename it to volume.lua, and store it in SCRIPTS/TELEMETRY on your SD card. A follow-up post will display the script so that you can copy and paste it into a text editor if you wish.
     
  • The GV that you use for volume control needs to be set to "Flight mode 0 value" in flight modes FM1 through FM8.


     
  • On the Inputs page, create an input to read the volume global variable. In this example I use [I7]:
    Code:
    [I7]Vol MAX Weight(GV1) [Volume]
     
  • On the Special Functions page, create a function to set the volume. You can put it in any open special function slot:
    Code:
    SF3 ON - Volume([I7]Vol)
  • At the bottom of the Telemetry page, set volume as a telemetry screen:


     
  • This first version of the volume-setting screen is deliberately made as simple as possible.
    • Press PAGE to get to the volume setting screen.
    • A beep with each press of the PLUS(+) or MINUS(-) button provides an audible indication of the volume.
    • A no-frills bar graph provides a visual indication.
    • Hold down PLUS(+) or MINUS(-) for faster volume change.
    • Press PAGE to switch to other telemetry pages.
    • Long-press EXIT to return to the regular screen.
       

     
  • Here's a bonus feature: If your first telemetry screen displays numbers...
     


    ... you can jump from that screen to the volume setting screen and begin changing the volume just by pressing PLUS(+) or MINUS(-).

One final note:

There's a function in the script that produces a tone to monitor the volume as you're adjusting it:
Code:
playTone(800, 50, 0, PLAY_NOW, 0)
The first parameter is 800, which sets the tone frequency to 800 Hz.

If you choose to modify the script to produce tones of varying frequency, beware of accidentally calling playTone() with a first parameter of zero because that will crash and reset the OpenTX operating system.
Last edited by Miami Mike; Apr 25, 2017 at 08:26 AM.
Sign up now
to remove ads between posts
Mar 26, 2017, 12:30 PM
Registered Taranis User
Miami Mike's Avatar
Code:
--[[ Volume Control, Version 1.0, for OpenTX version 2.1.9,
	by Miami Mike, March 26, 2017 ]]--

local GV = 1 --[[ This is the global variable that stores the volume setting.
On the Flight Modes page, set it to "Flight mode 0 value" in FM1 through FM8.

On the Inputs page, create an input to read the volume global variable.
Example: [I7]Vol MAX Weight(GV1) [Volume]

On the Special Functions page, create a special function to set the volume.
Example: SF1 ON - Volume([I7]Vol)
]]--
local Volume
local EVT_PLUS_HELD = 68; local EVT_MINUS_HELD = 69 -- key event constants.

local function init_func()
	Volume = model.getGlobalVariable(GV - 1, 0)
end

local function bg_func()
end

local function SetVolume()
	model.setGlobalVariable(GV - 1, 0, Volume)
	playTone(800, 50, 0, PLAY_NOW, 0)
end

local function run_func(event)
	if event == EVT_PLUS_FIRST or event == EVT_PLUS_HELD then
		Volume = Volume + 1
		if Volume > 100 then
			Volume = 100
		end
		SetVolume()
	elseif event == EVT_MINUS_FIRST or event == EVT_MINUS_HELD then
		Volume = Volume - 1
 		if Volume < -100 then
			Volume = -100
		end
		SetVolume()
	end
	lcd.clear()
	lcd.drawRectangle(5, 7, 202, 50, 0)
	lcd.drawFilledRectangle(6, 8, 100 + Volume, 48, 0)
end	
return { run=run_func, background=bg_func, init=init_func }
Latest blog entry: Taranis: Aileron-To-Rudder Mix.

Thread Tools