Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: Ron Ginger on May 01, 2018, 07:52:40 AM
-
I have built a panel with several buttons and a PoKey56E. I want two buttons to be a toggle for spindle on/off in forward and reverse. I used this code in the signal script.
[mc.ISIG_INPUT7] = function (state)
if (state == 1) then
mc.mcCntlSetLastError(inst, "Spindle Forward Off");
mc.mcSpindleSetDirection(inst, 0);
else
mc.mcCntlSetLastError(inst, "Spindle Forward ");
mc.mcSpindleSetDirection(inst, 1);
end
end,
Problem is when the button is pressed the signal is called and the function turns on, but as soon as the button is released the signal script sees the change and call the function again, turning the spindle off.
Any idea how to handle this? Is there a way to only see the signal when it rises, not on any change?
-
This is what I'm currently using on a machine here in the shop. I haven't look at it in a while, this script can probably be updated. But it is working like you want. Push on/Push off.
------------Input 3----------------
--------Toggle SpinCW()-----------
[mc.ISIG_INPUT3] = function (state)
if (state == 1) then
local inst = mc.mcGetInstance();
local sigh = mc.mcSignalGetHandle(inst, mc.OSIG_SPINDLEON);
local sigState = mc.mcSignalGetState(sigh);
if (sigState == 1) then
mc.mcSpindleSetDirection(inst, 0);
else
SpinCW()
end
end
end,
-
Hi,
a toggle button has two states and therefore requires two scripts.
One script will cause the spindle to start and the other will stop it.
As an example have a look at the Enable/Disable button in Mach4 wx4 screen set.
Craig
-
Thank you Cbyrdtopper that works perfectly. I also did the equivalent for reverse.
That was the last problem on my new control I have built for a friend to replace a dead Centroid.
-
Aweseome! Glad that worked out for you then!
-
Hi,
I have a little code that does things a little differently.
First I set up two toggle buttons, one ON/OFF and one FWD/REV. Note there is no need to put them in the signal library, they can be attached direct to an input signal,
I chose ISIG_INPUT10 and ISIG_INPUT11 respectively and these can in turn be assigned to a pin which is hooked to your external toggle switches.
There a four fragments of code, an 'up' script and a 'down' script for each button. I arbitrarily chose OSIG_OUTPUT4 for spindleON/spindleOFF and OSIG_OUTPUT5 for FWD/REV
ON/OFF up script:
local inst=mc.mcGetInstance()
local hsig=mc.mcSignalGetHandle(inst,mc.OSIG_OUTPUT4)
mc.mcSignalSetState(hsig,1)
ON/OFF down script:
local inst=mc.mcGetInstance()
local hsig=mc.mcSignalGetHandle(inst,mc.OSIG_OUTPUT4)
mc.mcSignalSetState(hsig,0)
FWD/REV up script:
local inst=mc.mcGetInstance()
local hsig=mc.mcSignalGetHandle(inst,mc.OSIG_OUTPUT5)
mc.mcSignalSetState(hsig,1)
FWD/REV down script:
local inst=mc.mcGetInstance()
local hsig=mc.mcSignalGetHandle(inst,mc.OSIG_OUTPUT5)
mc.mcSignalSetState(hsig,0)
Achieves the same result but uses the properties of the screen toggle button. Note if you want to be super code efficient you can attach an output directly to a toggle button so you don't even
have to write any scripts. I know.....where's the fun in that!
Craig
-
Hello
I had a bit of a play, and having very limited script knowledge, I've developed the following script which uses the status of Output 1 LED to either toggle the spindle on or off.
'Spindle Toggle ON/OFF
If GetLED(Output1) <> 1 Then 'Is Output 1 enabled?
DoSpinStop 'If YES Turn OFF Spindle
DeactivateSignal(OUTPUT1) 'And Disable Output 1
End If
If GetLED(Output1) <> 0 Then 'Is Output 1 disabled?
DoSpinCW 'If YES Turn ON Spindle
ActivateSignal(OUTPUT1) 'And Enable Output 1
End If
-
That looks like VB not lua :) and looks like Mach3 calls.
-
Right you are, didn't fully read the subject link.
-
No problem man! Just wanted people to know when they saw it!