I am fairly new to redstone, and I would like some help. I started building an automated railroad crossing: the lights and gates work fine, but I do not know how to implement a system that would decide when to raise or lower the gates. (The gates are controlled by a pulse the length of the press of a wooden button, but the lamps require constant power.) There are 4 detector rails on the track that send their signal to the central system. The attachment shows their layout.
When a minecart passes either of the two farthest detector rails from the crossing, the system should activate. It should deactivate once the minecart passes one of the two detector rails closest to the crossing.
For example, let's say the minecart is travelling from the left to the right (please see the image). When it passes the first detector rail from the left, the gates are lowered. However, when it touches the second detector rail from the left, nothing happens as the minecart has not yet cleared the crossing. Finally, when the minecart passes over the third detector rail from the left, the gates are raised. Furthermore, it is important that when passing the fourth detector rail from the left, the minecart doesn't make the system reactivate. The scenario would be the opposite when the minecart is coming from the other direction.
Ultimately, I would be very grateful for any help on how such a system could be built.
I think I'd try splitting it up into 2 identical circuits, one with detector rail #1 and #3 and the other with #2 and #4 (numbered from left to right.
Then I think the circuits should have 3 states, A, where nothing is activated. (It's just waiting for a minecart.)
If rail #1 (or #4 for the other circuit) detects a minecart the circuit switches to state B, where it activates the gates and lamps and waits for #3 (#2) to detect the minecart which puts it back in state A (with gates and lamps deactivated.)
If, on the other hand rail #3 (#2) detects the cart first it switches to state C where it just waits for rail #1 (#4) which switches it back to A (without activating gates and lamps.)
Does that make any sense?
I'd have to do some more thinking to figure out in more detail how to implement it. (It's bedtime now.)
An alternative that might be easier to set up if you know about how fast the cart will be moving and know that there won't be another cart, from either direction too soon, would be a redstone timer started by rail #1 that disables the signals from #2 and #4 for long enough for the cart to pass #4.
And likewise a timer started by #4 that disables #3 and #1.
Thanks for the idea! Actually, I came up with another one based on yours, so thanks again! I managed to put together the circuit that can be seen in the attachment, and it works perfectly. Now, I just need to integrate that with the railroad crossing. (Yes, I know, it is very messy! I will try to make it more compact...)
Well... it didn't quite work out! When I tried to integrate the system with my gates, lights, and the railway line, things malfunctioned. After a lot of time, I figured out that the counter circuit was the culprit (blue and pink circuits), so I've replaced it with a better and more compact design. Then I hooked everything up, and it finally worked! Okay, most of the time... When a minecart would travel alone, the system would work, as minecarts without entities in them are slower. However, when I sat in the minecart, the feedtape system (gray and red circuits) broke because it received inputs too fast. And right now, it just dawned on me that there is absolutely no need for the feedtape system as the counter system can replace it. So I am basically back to the drawing board... At least now I know how to make everything way more compact.