Experimenting with code functions

Im wanting to have a digital pin wait for an input (pulseIn) say HIGH and once the signal changes back low I want to change the state of the receiving pin to an output and then transmit a pulse.

The Idea is to use 1 digital pin like a handshake between an Arduino running GRBL and a Tool changer
the idea is to have GRBL transmit a pulse of a fixed duration say 2 seconds (not important just long enough for the tool changer to recognise it).

The receiving Arduino (Pin) then changes from an input to an output and then transmits a continues pulse until a boolean state is changed in code which switches the output off again.

The GRBL Arduino would be coded to transmit only the 2 second pulse then switch to listen.

This way if a tool change is required Grbl transmits a signal then reverts to listening to the pin as long as the signal is High for example then it knows the tool changer is busy. Once the tool changer has completed its task it drives the signal low then becomes an Input pin again. On seeing this pin change GRBL continues with its milling operation.

The UNO version of GRBL only has 1 spare pin which happens to be A4.

Overall Plan.

What the overall project might look like is that the serial commands sent to grbl will be bridged to a second usb using a virtual serial port application. The tool changer arduino will listen for tool change instructions in transmitted gcode and parse out the Tool commands M6 and T* (* = the tool number)
This cant instigate a tool change as the values read into the GRBL buffer means that it is not finished all of its operations just because it has changed a tool change instruction and would need to instigate the operation when it was ready - The tool changer needs to tell GRBL its finished.
As the code advances the M6 T* gcode will tell the tool changer arduino what tool its expected to load so when it receives the go/ active pulse it will use that information to offer the correct tool.
The rest will be sensors for extend and retract of the changer motors for extend and retract, sensors to see tool clear and tool loaded, limit switches and a tool location ID sensor (check tool is aligned with spindle and not half cocked. Possibly an encoder to offer belt and braces for the tool number/location, Once homed the stepper should be able to know where it is but if it lost steps may not offer the correct tool and carnage will happen.
The reset pin will be daisy chained with the grbl arduino so any alarm will kill the operation on both Arduinos.

What have you tried so far ?

using a single line for both transmission and reception is common in half-duplex communication and in particular with RS-485.

sounds like you're describing the master that polls a slave device, either sending a command or giving it a chance to send something. But when the slave is given a chance to respond it must do so within a limited amount of time.

the grbl protocol suggests that the communication is ascii strings presumably using the USART. But there is a 2nd pin used to indicate busy.

the Serial flush() function returns after transmission is complete so that you know when it is ok to switch from output to input.

JT007:
The UNO version of GRBL only has 1 spare pin which happens to be A4.

Do you know how to (or if it is possible to) get GRBL to produce a pulse on that pin at the correct time?

Figuring that out seems to be the first requirement.

In Arduino terms a 2 second pulse is FOREVER. 20 millisecs would be quite long.

I imagine a tool-change will only happen when none of the stepper motors is moving. Maybe you could identify that by monitoring the pulses on the step-pin of one or more of the drivers?

...R