dual function buttons (using press time check)

This is where you talk about Macros, show examples of your macro scripting and SHARE handy segments of script code as examples.

dual function buttons (using press time check)

Postby Battwell » Tue Sep 25, 2018 3:28 pm

IMG_4985.JPG
flowchart of button timed

an example of my code i wrote for a control panel- to give buttons a dual function depending on time the button is pressed.
it gives 1 function if pressed and released or a different function if pressed and held over 2.5 seconds.
it runs as a macroloop only . the code shown reads and writes to modbus but could easily be changed for wired i/o
also shows the new is macro already running code (works in latest test release only) - and its good thanks balacz.
as shown it will complile but wont run on your machine unless using the same registers etc- and it checks a timer to confirm no loss of communication.
(but it will be handy to get correct syntax to do these sort of things anyway ( im always looking for code examples to copy/paste into my macros!!!)
ps. as written it checks 8 buttons. change the loop numbers to check up to 99 buttons per loop :-)
Last edited by Battwell on Tue Sep 25, 2018 3:43 pm, edited 1 time in total.
Uc300eth on router and mill.
UK uccnc powered machine sales. https://cncrouter.uk/atc-cnc-routers.htm
Automateanything/duzzit cnc/mercury cnc
Battwell
 
Posts: 867
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk

Re: dual function buttons (using press time check)

Postby Battwell » Tue Sep 25, 2018 3:32 pm

m411.txt
(2.43 KiB) Downloaded 1229 times


here is the macro. hope it helps someone. (took me ages to work out how to do it in my head- hence rubbish sketch on paper i worked off :-)
Uc300eth on router and mill.
UK uccnc powered machine sales. https://cncrouter.uk/atc-cnc-routers.htm
Automateanything/duzzit cnc/mercury cnc
Battwell
 
Posts: 867
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk

Re: dual function buttons (using press time check)

Postby thesleepydog » Tue Feb 18, 2020 7:01 am

Thanks for sharing the macro, very interesting and helpful. :D I am relatively new to C#, but I have done a couple of courses online including the SoloLearn one.

Would you mind sharing why you use the following condition?
if (!((exec.Getvar(499)) == (exec.Getvar(498))))
instead of something like;
if(exec.Getvar(499)) != (exec.Getvar(498))

Not sure if there is something gained here by using the '!' at the start to flip the logic of the test in the if statement versus in the middle.
I think this might just be a personal coding style?
...Sorry if this is a stupid question... :oops:
thesleepydog
 
Posts: 15
Joined: Sun Mar 03, 2019 11:10 am

Re: dual function buttons (using press time check)

Postby Battwell » Fri Feb 21, 2020 2:14 pm

probably because im not a programmer. i play with syntax until it does what i want- then move on :-)
Uc300eth on router and mill.
UK uccnc powered machine sales. https://cncrouter.uk/atc-cnc-routers.htm
Automateanything/duzzit cnc/mercury cnc
Battwell
 
Posts: 867
Joined: Sun Sep 25, 2016 7:39 pm
Location: South Wales. Uk


Return to Macros

Who is online

Users browsing this forum: No registered users and 4 guests