I have a set of 5 pairs of LED lights which operate in sequence using a single switch and a switch/case statement that allows them to be lit in a sequence that mimics the train passing each signal in turn.
I have managed to add another pair of lights which mimics a branch line diverging part way along the main line. This sequence is operated by another switch and it works really well.
So this is the question - once either ot the switches has been pressed to start the sequence, how do I prevent the second switch from interrupting until the first sequence is complete.
Any ideas for a simple solution would be very much appreciated.
Read the how to use this forum-please read sticky to see how to properly post code. More member will see your code if the code is posted as described in the forum guidelines.
It appears your code has to state variables, 'mode_1' and 'mode_2' and it also appears that if these variables are 0, then the sequence has not started. You need to include a test for these variables along with the button press to only accept a button press if the other mode is 0, else ignore the button press
old
// Check if state changed from high to low (button press).
if((newState_1 == LOW) && (oldState_1 == HIGH)) {
//....
new
// Check if state changed from high to low (button press) and other sequence is not running.
if((newState_1 == LOW) && (oldState_1 == HIGH) && mode_2 == 0) {
//...
You will need to do this for the other button as well.