Push button relay toggle

I've just recieved my neuron L203 and began playing with the mervis software. In my house are only push button switches, so they don't keep the DI constantly on, instead, they give a short pulse (or long, is you keep pressing them).

How can I get this behavior to toggle a RO?

push > relay goes on

release > relay stays on

push > relay goes off

release > relay stays off

Even better... is there a way to detect the length of the push, or detect double clicks?

@Jan-Teunis Neurons have a direct switch function (see documentation) but it detects only rising/falling edges of the signal. Long presses has to be solved in mervis. So I suggest you to create your own function block, which will take care of it...

@SorakCz If you want just this functionality then use the Direct Switch. You do not have to program in ST anything and it reacts on every rising edge which mervis does not have to catch (you could try to detect the pushes via counters thought)

Hi,
With the following program, If I "short" push the button, the final out value goes 0 or previous analog value. If I "long" push the button the value increase or decrease.
So I have short and long push detection and a toggled output.
This is working pretty well with 50% ratio.

@kolopes The asnwer is above. The best is to use the DirectSwitch function (set variables DS_enable and DS_toggle to True). The number of DI(button) must be the same as RO. You can enable this functionality for each pair of DI-Ro/Do. Make sure to set the NV_save variable of the group where this will be configured to True and False afterwards.

To be able to set the values, you have to be in debug mode!

Alternative approach is to write your own function block that might do much more...

@sgtgarcia Direct Switch is a feature of HW of Neuron, it's not a feature of Mervis (but it can be of course programmed for such behaviour). To enable DS, check Mervis variables that start with "DS_" there you will find the DS_enable, DS_toggle and DS_polarity functions.