You are using the functionality of a state-machine with variable situation.
There is another kind how to create a state-machine.
This other kind uses the switch-case-break-statement
I bolded the word break to emphasise that the "break"-command is
very important
to make it work
Your functions
//Day or Normal situation
if (situation = 1) {
green_lightNS();
delay(DELAY);
yellow_lightNS();
delay(DELAY);
red_lightNS();
delay(DELAY);
green_lightEW();
delay (DELAY);
yellow_lightEW();
delay(DELAY);
red_lightEW();
}
etc. use delay. This must be changed to not use delay but non-blocking timing.
If you want highest responsivness this code must be changed to use its own state-machines too
The state-machine will enable NON-blocking timing
see the both words non-blocking ---------------- and --------------------- timing
Executing things from time to time like switching on / off LEDs
but in a non-blocking way
The key to this is to jump-in / jump-out of a function very quickly
You have to learn two things:
- learn how non-blocking timing works
- learn how switch-case-break state-machines work
Your state-machines will have time-based transistions from state to state
This will realise that your LEDs will bei switched on / off in the same timely manner as before but with instant reaction on button-presses.
Be the change you want to see in the world
best regards Stefan