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.