Guidance on controlling model railway signals with simple time-based changes

Hello there, I am new to the Arduino so it's a bit of a steep learning curve to start off, considering the last coding I did was in BASIC in about 1984!

I've been reading up and studying a few other similar projects on-line, but they look complicated and I really need a bit of advice to get started. So far I only know a few common commands as I'm working through an instructional book, but I'd like to get started writing a sketch (best way to learn probably) so using the most appropriate commands from the start would be helpful.

To this end, this is what I am trying to accomplish: I have a signal with red, amber and green aspects. The aspect is normally green but when a passing train triggers an IR detector in the track, the aspect changes to red. It stays red for x seconds and then changes to amber for x seconds and then back to green. Now that is pretty easy - in fact I've muddled through a sketch which achieves just that (using if else statements) but relies on the delay command which as I understand it, is not a good approach. Also I have two additional requirements, firstly, a manually operated switch which sets the signal to red and stays on that aspect until the switch is switched back. Secondly should a train pass the signal at amber the aspect needs to change to red again and the sequence restarts.

I would be grateful for some pointers on the approach and commands that I need to use. Many thanks

What you should Google is a "state machine".

Also look at this

Thank you, I will have a look.

Have a look at how millis() is used to manage timing without blocking in Several Things at a Time.

And see Using millis() for timing. A beginners guide if you need more explanation.

And do read about the concept of a state machine. It is just a fancy name for one or more variables that keep track of the state the program is at.

...R