Page 1 of 2

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

PostPosted: Tue Jul 23, 2024 6:49 pm
by bhdavis
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

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

PostPosted: Wed Jul 24, 2024 11:17 pm
by bhdavis
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

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

PostPosted: Thu Jul 25, 2024 9:57 am
by bhdavis
Will a MACROLOOP accomplish this?

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

PostPosted: Thu Jul 25, 2024 10:48 am
by ger21
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,###);
}

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

PostPosted: Thu Jul 25, 2024 11:19 am
by bhdavis
Thanks Gerry. Will give it a go this morning.

BH

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

PostPosted: Fri Aug 23, 2024 3:50 pm
by bhdavis
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

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

PostPosted: Sat Aug 24, 2024 12:06 am
by bhdavis
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

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

PostPosted: Sat Aug 24, 2024 12:39 pm
by dezsoe
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
}

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

PostPosted: Sat Aug 24, 2024 1:02 pm
by bhdavis
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

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

PostPosted: Sat Aug 24, 2024 1:38 pm
by bhdavis
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