Variable Numeric SlotSensor
Variable Numeric HomeAxis
Variable Numeric DestX
Variable Numeric DestY
Variable Numeric DetachMM
Variable Numeric SpeedSearch
Variable Numeric SpeedReturn
Variable Numeric InitialPosition

Label Home
	' -------------------------- detach if sensor is active
	If Slot(SlotSensor) > 500 Or Key("CTRL")
		If HomeAxis = 0
			DestX = DestX + DetachMM
		Else
			DestY = DestY + DetachMM
		EndIf
	EndIf
	' -------------------------- search home
Label SearchHome
	If HomeAxis = 0
		DestX = DestX + SpeedSearch
	Else
		DestY = DestY + SpeedSearch
	EndIf
	'
	Wait Seconds 0.005
	If Slot(SlotSensor) > 500 Or Key("CTRL")
		Beep
	EndIf
Goto SearchHome
    ' -------------------------- detach from the sensor
Label DetachSensor
	If HomeAxis = 0
		DestX = DestX + SpeedReturn
	Else
		DestY = DestY + SpeedReturn
	EndIf
	Wait Seconds 0.005
	If Slot (SlotSensor) < 500 Or Key("CTRL")
		Beep
		Goto MoveToInitialPosition
	EndIf
Goto DetachSensor
    ' -------------------------- move to InitialPosition
Label MoveToInitialPosition
	If HomeAxis = 0
		DestX = InitialPosition
	Else
		DestY = InitialPosition
	EndIf
Return




'WATCH v1
'EXEC DestX = 12
