 # MG 400 Push button Help

#1

I’m developing code that goes to points after a button is pressed and it works but for some reason if the button was pressed while the code was already started it does not wait for the button to be pressed again instead it starts automatically as if just skips a few lines of code. my code is below.

MovJ((safe))
while 1 do

while not (DI(5)==1) do
Sleep(1)
end
while not (DI(5)==0) do
Sleep(1)
end

MovJ((StartPos))
for count = 1, math.floor(NumberOfParts) do
while not (count==9) do
Jump((RelPoint(HoleLocation[count],{(offsetXi),(offsetYi),0,0})), {Start=JumpHeight, ZLimit=MaxHeight, End=JumpHeight})
Wait(500)
count = count + 1
print(count)
end
i = i + 1
end
MovJ((safe))
i = 0
Started = 0
end

#2

Change to:

MovJ((safe))
Sync()
while 1 do

while not (DI(5)==1) do
Sleep(1)
end
while not (DI(5)==0) do
Sleep(1)
end

MovJ((StartPos))
Sync()
for count = 1, math.floor(NumberOfParts) do
while not (count==9) do
Jump((RelPoint(HoleLocation[count],{(offsetX i),(offsetY i),0,0})), {Start=JumpHeight, ZLimit=MaxHeight, End=JumpHeight})
Sync()
count = count + 1
print(count)
end
i = i + 1
end
MovJ((safe))
Sync()
i = 0
Started = 0
end

#3

Thank you that fixed my problem! for future reference what does Sync() do

#4

This is difficult to explain. it simply blocks the scan of the logical operation and waits for the end of the motion to scan down