Page 1 of 3
Long push on button
Posted: Mon Mar 03, 2025 8:43 am
by Nico595
Hello,
I need a long push on button function. Have you idea to do the long time push button ?
When I click on the button with long push, I want repeat the execution of the macro. I can't find parameter in the button to do it.
It's like you up the volume of your music player.
I use the same button in the "simple com sender" project. This "button" come from "Creation".
Thank you so much.
Re: Long push on button
Posted: Mon Mar 03, 2025 9:05 am
by medelec35
What I do for long and short press detection is have a loop with a counter, timeout and a delay that continues all the time the button is pressed.
All the time the button is pressed the loop will continue until the button is released or the loop count is over a certain value i.e. for timeout.
Just after the loop if the loop count over a fixed value then its along press, otherwise it's a short press.
Re: Long push on button
Posted: Mon Mar 03, 2025 9:31 am
by Nico595
Thank you Martin for your fast answer
If I understand good, no parameter in the button exist to do it.
I use your method in my embedded project, it work fine with a keyboard interrupt.
With PC App the macro is firstly called by the button and it's very good. We don't need check the state of the button every time in the App.
But with a long push function we must check the state of the button to call the macro.
If the macro of the button is not called by the button, the macro process maybe disconnected by other process. It's again a problem with the priority level. When the macro is called by the button, the macro process is run in first time, probably with the high level priority.
Can you customise proprieties of this button to obtain the long push parameter with repeat the called macro ?
Like this we keep the high level priority of the process for the last pushed button.
Re: Long push on button
Posted: Tue Mar 04, 2025 8:55 am
by Nico595
I find a solution in mixing two macro with interrupt on the long push macro. Work fine some minutes and the Interrupt stop without reason.
I added a simple counter on the "Simple Com Sender". Push on "Interrupt" button, you can see the interrupt itself stopped around 1300, 2600 ...
Have you this problem ?

- Capture_2025-03-04 101027.png (18.97 KiB) Viewed 8167 times
Thank you for your support.
Re: Long push on button
Posted: Tue Mar 04, 2025 10:16 am
by mnfisher
One thing to try:
Move NumericIndicator1:SetValue(compt_test1) to the loop in main. I'm not sure about app developer - but in general you need to keep interrupt handlers as short as possible (if another interrupt occurs before the handler is finished then the code will lock up...)
I cranked up the interrupt rate a bit and it runs for longer (counts to 6000 then resets) - and repeats... If it locks - and it seems to eventually then the code seems to be still running.. I added a simple 'flashing' indicator - and that flashes even after the counter stops being updated (so maybe a bug in the numeric indicator? - or the timer interrupt stops?)
Martin
Re: Long push on button
Posted: Tue Mar 04, 2025 10:26 am
by Nico595
Hi Martin
Thank you so much for your answer, I will try it.
Re: Long push on button
Posted: Tue Mar 04, 2025 11:07 am
by mnfisher
I also tried tying the flash to comp_test1 - in this case the LED stops flashing so it looks like it's a problem with the interrupt code.
Martin
Re: Long push on button
Posted: Tue Mar 04, 2025 11:11 am
by Nico595
Your var ".i" is no incremented by the interrupt but by the main. I placed "i" var in the macro started by the interrupt.
Work if you don't push button but when you push a button like "Vol Up" the interrupt is stopped.
I think the delay is also a problem in the main.
Re: Long push on button
Posted: Tue Mar 04, 2025 11:16 am
by medelec35
I have recently looked into timer interrupts with PC Developer.
Conclusion is mentioned
here.
Re: Long push on button
Posted: Tue Mar 04, 2025 11:25 am
by Nico595
Hi Martin,
So, we can't use the Interrupt without your trigger ?
I use successfully the Interrupt in my embedded project, it work fine but because we can set the level priority of the Interrupt in the C code. Without Interrupt we can't design a a big project.
The problem about Interrupt in PC App that we have no priority level, the Interrupt are stopped by push on button or by the main.
I checked the updated project with "i" in counter macro, same problem. Without delay in the main, the Interrupt was not stopped by push on button but stopped in the time without reason.