LUA function script set channel

openTx has introduced a range of new features, ideas and bling. It is fast becoming the firmware of choice for many users. openTx will run on ALL current hardware platforms, including the gruvin9x and sky9x boards. Work has already started to support the new FrSky X9D radio!
Post Reply
Fiesel
Posts: 2
Joined: Mon Aug 18, 2014 7:47 pm
Country: -

LUA function script set channel

Post by Fiesel »

Hi,

I'm trying to code what I thought was a simple task.
When I flip the momentary switch on my taranis, I want to set Channel 2 on my taranis to max value for a specific time (200ms). I know I can do this woth logical switches and functions, but the script will do some more calculations in future.

This is what I have come up with so far:
local running = false
local duration = 20 -- ticks for 1 turn. 1 tick = 10ms
local initvalaxis
local starttime

local function run()
        -- start movement
        if not running then
                running = true
                starttime = getTime()
                initvalaxis = getChannelValue(CH2) -- does not exist!
        end

        -- move
        setChannelValue(CH2, 1024) -- does not exist!

        -- end movement
        if getTime() >= starttime + duration then
                running = false
                setChannelValue(CH2, initvalaxis) -- does not exist!
        end
end

return { run=run }
I thought I bind this script to a special function to execute when i flip SH and then I'm good to go. BUT: I can't find the commands to get and set current channel values.
Can't function scripts do that? What will I have to use? A mixer script? That scripts are way more complicated :/
Is there a way to set a logical switch from a function or one-time script? this way I could do some calculations and set logical switches accordingly which I could bind to override channels in special functions menu...
Or is there any other _simple_ way I have not thought of yet? or any example scripts which do similar things? Or am I asking for hale in the wrong forum? Where lives all the opentx lua development community?

Thank you in advance :)

User avatar
Kilrah
Posts: 11109
Joined: Sat Feb 18, 2012 6:56 pm
Country: Switzerland

Re: LUA function script set channel

Post by Kilrah »

It has to be a mixer script.
AlexF
Posts: 10
Joined: Tue Dec 08, 2015 9:40 pm
Country: -

Re: LUA function script set channel

Post by AlexF »

Hi Fiesel,

did you make any progress?

I have a very similar question like you.

Post Reply

Return to “openTx”