Before I bring the sketch from my real layout, in this post I will give a general solution. It is quite workable and you can apply it in your designs.
In this example, I use a variable of byte type to write the state of the rail blocks. As a result, we are able to transmit this number via bus I2C or serial port. It also makes it possible to perform mathematical operations with data (see the end of the sketch). The principle of recording data in the pictures below.
See my site for more details.
Without DDС management, only Open components. Please comments!