In a few weeks I need to assign different functions to one momentary button.
Normally that is done by using a counter to count the times that the button is pressed.
You use a variable and store that and every time you press the button, that variable is incremented by one and stored again, and so on.
BTW: the button is not a hardware button, just a button with a dataref. So no bouncing ??????
This is the code I use:
Code: Select all
function add()
local start = 0
local old_start = 0
local page1 = 0
old_start = persist_get(ctr_begin)
print("old_start is " .. old_start)
start = old_start + 1
persist_put(ctr_begin, start)
--0 = mapmode....1 = ctr page ... 2 = ctr page with VSD
end
function pushbutton(ctr_pb)
if ctr_pb == 1 then --tested also with pb ~= 0
my_timer = timer_start(1000, nil, add)
end
end
xpl_dataref_subscribe("laminar/B738/EFIS_control/capt/push_button/ctr", "INT", pushbutton) --ctr_pb
old start is 4
old start is 3
old start is 2
old start is 1
old start is 0
It seems as if here some bouncing is going on but again, it's not a hardware button and " old_start " always ends with 4.
Can someone explain to me where I am going wrong.
I use AM3.3 beta.
Have Fun
Jedeen