Gcode endstop experiment

What is the problem?

Good day! I'm new to GCODE. I have an old 3D printer with an Anet A1284-base board. For my project, I would like to do a little experiment before I start redoing the mechanics. What I want to do:
When you launch a GCODE file through the regular printer menu from SD card, the X axis moves 1 cm in any direction, freezes for 5 seconds and moves back. After that, I press the limit switch of the Z axis with my finger and the Z axis moves 1 cm in any direction. I release the limit switch and the Z axis returns back. Ideally, this action should be repeated indefinitely. Is it possible to do this? Please help me figure this out. Thank you!

What did you already try to solve it?

I tried this code. Does not work!
G91 ; Set relative coordinates
G1 Z-10 F100 ; Move the Z axis down 10 mm at a speed of 100 mm/min
M400; Wait for the movement to complete
M119; Check the condition of the Z axis limit switch
IF [Z_MIN] = 1 ; If the Z-axis limit switch is turned on
G91 ; Set relative coordinates
G1 Z360 F100 ; Make the Z axis motor 20 revolutions at a speed of 100 mm/min
G90 ; Return to absolute coordinates
ENDIF

Have you tried running in safe mode?

WRITE HERE

Did running in safe mode solve the problem?

WRITE HERE

Systeminfo Bundle

You can download this in OctoPrint's System Information dialog ... no bundle, no support!)

WRITE HERE

Additional information about your setup

What kind of hardware precisely, OctoPrint version, OctoPi version, printer, firmware, browser, operating system, ... as much data as possible

WRITE HERE

This seems like something you need to do in the Firmware for the printer. The IO points for the end stops is part of that system. It would have to report the status in some way for a plugin to know what was happening at the printer. There is some Marlin GCode that might get that info for you but i think it also puts the printer in some kind of debug mode.

Why is it that a standard Home of the Axis system does not solve whatever it is that you are attempting to solve?

As far as I know of you cannot use if-then statements in G-code.

You could not do this with standard gcode as there is no flow control like the if statements you're using. Modifying the firmware to run this routine would be possible (if you can understand it & write c++), or creating a plugin for OctoPrint that handled the control.

Because first I need to press the limit switch button with my finger and then the engine should start, and not vice versa by moving to the button and pressing it.

yes, that’s the problem, she doesn’t understand IF and GOTO. I can't think of another condition operator

for example this code does not work

; Настройка концевика Z для запуска скрипта
M581 Z S1 T1

; Повторять следующие команды
:start
G91 ; Установить относительное позиционирование
M400 ; Дождаться завершения всех текущих движений
M581 Z S1 T1 ; Установить триггер T1 на активацию концевика Z
M582 T1 ; Проверить триггер T1

; Команды, выполняемые при активации T1
M400 ; Дождаться завершения всех текущих движений
G1 Z8 F100 ; Переместить ось Z на 8 мм (или нужное значение) с заданной скоростью
G90 ; Установить абсолютное позиционирование
GOTO start ; Вернуться в начало скрипта

I think the installation of a proper firmware would be way more easy.

Are there any technical details about the printer board?

FIRMWARE_NAME: Marlin V1; Sprinter/grbl mashup for gen6 FIRMWARE_URL:GitHub - ErikZalm/Marlin: Reprap FW with look ahead. SDcard and LCD support. It works on Gen6, Ultimaker, RAMPS and Sanguinololu PROTOCOL_VERSION:1.0 MACHINE_TYPE:I3 Pro B EXTRUDER_COUNT:1 UUID:00000000-0000-0000-0000-000000000000

They do not exist in gcode. It doesn't have conditions, nothing like this. It is not possible with gcode.

You cannot do what you would like with gcode. You must either write some custom code to interpret the responses, in a plugin, or rewrite the firmware.