Creating a TOGGLE screen button to turn an output on and off

Post anything you want to discuss with others about the software.

Creating a TOGGLE screen button to turn an output on and off

Postby bhdavis » Tue Jul 23, 2024 6:49 pm

I have several devices I want to be able to turn on and off with buttons on the UCCNC 1.2113 screen. The buttons will control an output on my C76 control board.

I've created macros to turn these features on and off. One macro turns it on and a second one turns it off. As such I can type the macro name into the MDI and activate the feature. But I want to be able to do it with the mouse on screen so need the buttons.

I've created an up/down button image for each of the three features. I can make either the up or down image show by changing the state to true or false in the screen editor. I currently have that set so the OFF image (no green perimeter) is showing.

I've assigned a macro to activate the output in the 20000 to 21999 range for each of the three features.

When I click the new screen button the output on the C76 activates and the needed feature turns on. However the button image does not change top the green border ON state and pressing it a second time does not turn off the feature. Obviously this is because my macro tied to the new screen button is the ON macro.

So I can solve this one of two ways that I know of:

1) Make two buttons for each feature, one for the ON macro and one for the OFF macro.

or...............

2) Figure out how to do a toggle with the single button so it turns the output on when depressed and off when depressed a 2nd time. Just like turning the spindle on and off with the CW spindle toggle for example. But I haven't been able to figure out how to do that. For reference I have them set at:

BLINK=FALSE ......... TOGGLETYPE=TRUE...........ISON=FALSE

I know that certain button numbers are reserved for certain types of functions so perhaps that has something to do with it.

Perhaps I can do it in the macro? Maybe something similar to this that turns my spindle off at the end of a predetermined warmup period:

}

// stop the spindle
exec.Stopspin();

// switch the state to "off"
AS3.Switchbutton(false, 20001);
AS3.Setfieldtext("OK", 20001);
}

Thanks,
BH
bhdavis
 
Posts: 141
Joined: Tue Mar 23, 2021 7:36 pm

Re: Creating a TOGGLE screen button to turn an output on and

Postby bhdavis » Wed Jul 24, 2024 11:17 pm

Well I've created the screen with 2 buttons, one for activating the output and one for deactivating it. All works fine but it would still be nice to know if this could be done with a single button.

Thanks,
BH
bhdavis
 
Posts: 141
Joined: Tue Mar 23, 2021 7:36 pm

Re: Creating a TOGGLE screen button to turn an output on and

Postby bhdavis » Thu Jul 25, 2024 9:57 am

Will a MACROLOOP accomplish this?
bhdavis
 
Posts: 141
Joined: Tue Mar 23, 2021 7:36 pm

Re: Creating a TOGGLE screen button to turn an output on and

Postby ger21 » Thu Jul 25, 2024 10:48 am

Replace ### with the button number, and save the macro with the button number as the name:

Code: Select all
bool buttonstate = AS3.Getbuttonstate(###);

if (buttonstate)
{
   AS3.Switchbutton(false,###);
}
else
{
   AS3.Switchbutton(true,###);
}
Gerry
UCCNC 2022 Screenset - http://www.thecncwoodworker.com/2022.html
ger21
 
Posts: 2714
Joined: Sat Sep 03, 2016 2:17 am

Re: Creating a TOGGLE screen button to turn an output on and

Postby bhdavis » Thu Jul 25, 2024 11:19 am

Thanks Gerry. Will give it a go this morning.

BH
bhdavis
 
Posts: 141
Joined: Tue Mar 23, 2021 7:36 pm

Re: Creating a TOGGLE screen button to turn an output on and

Postby bhdavis » Fri Aug 23, 2024 3:50 pm

Gerry,

It's taken a while but I've finally gotten back to trying to figure out the toggling button.

With your code above I've successfully gotten a button to toggle on and off. However that is just changing the state of that button without it actually turning any physical item on and off. That's where I'm stumped.

Toggling that button needs to activate the following:

First press:
exec.Setoutpin(4,17); // Move the ATC table out to the load position
or
M2701 which includes that line of code.

AND

Second press:
exec.Clroutpin(4,17); // Move the ATC table to the park position
or
M2702 which includes that line of code.

I've experimented with various ways to try and integrate the table movement code with the toggling code but obviously am missing something.

Thanks,
BH
bhdavis
 
Posts: 141
Joined: Tue Mar 23, 2021 7:36 pm

Re: Creating a TOGGLE screen button to turn an output on and

Postby bhdavis » Sat Aug 24, 2024 12:06 am

What I've mainly been trying is putting an if/else statement below the bool statement that will look at button 20020 and activate M2701 or M2702 depending on the state of 20020.

Is that the correct way to attack this?

BH
bhdavis
 
Posts: 141
Joined: Tue Mar 23, 2021 7:36 pm

Re: Creating a TOGGLE screen button to turn an output on and

Postby dezsoe » Sat Aug 24, 2024 12:39 pm

Just combine the codes:

Code: Select all
bool buttonstate = AS3.Getbuttonstate(###);

if (buttonstate)
{
   AS3.Switchbutton(false,###);
   exec.Clroutpin(4,17); // Move the ATC table to the park position
}
else
{
   AS3.Switchbutton(true,###);
   exec.Setoutpin(4,17); // Move the ATC table out to the load position
}
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Creating a TOGGLE screen button to turn an output on and

Postby bhdavis » Sat Aug 24, 2024 1:02 pm

Thank you !! That did the trick.

I actually tried that but it didn't work. Then it also didn't work the first time I tried it pasting in your code. But I'm away from the shop so working in Demo mode. Once I closed and reopened UCCNC it worked as it should. So maybe I was closer than I thought to getting it to work.

Thanks Dezsoe. Much appreciated.

BH
bhdavis
 
Posts: 141
Joined: Tue Mar 23, 2021 7:36 pm

Re: Creating a TOGGLE screen button to turn an output on and

Postby bhdavis » Sat Aug 24, 2024 1:38 pm

Thanks everyone. Here are the results. This is just in Demo mode but the LED IS turning ON/OFF so I'm going to assume it will work as it should on the router.

You can see Port 4 / Pin 17 LED changing state with the bottom left ATC TABLE button change.

Thanks !!!
BH


out 4.17 true.jpg


output 4.17 false.jpg
bhdavis
 
Posts: 141
Joined: Tue Mar 23, 2021 7:36 pm

Next

Return to General discussion about the UCCNC software

Who is online

Users browsing this forum: Bing [Bot] and 5 guests