Approach Island Approach RR Crossing

I'm in the process of working on an island approach island railroad crossing circuit sing three track circuits. The inputs are five-volt pullup signals, and the outputs go to a relay shield to drive the lights and bell. This is the code I have so far and need some help to clean it up and get it working like the real thing. I've seen the concept done with analog sensors but can't find it being done the traditional way with three digital "switches" per say since that's what track circuits are.

//THIS CODE IS DESIGNED TO REPLICATE A TRADITIONAL ISLAND APPROACH ISLAND RAILROAD CROSSING CIRCUIT THAT WILL BE USED FOR A 1/8 SCALE MODEL RAILROAD AND FUNCTION PROTOTYPICALLY TO THE REAL CIRCUIT
//

#define NORTH_APPROACH 5
#define ISLAND_CIRCUIT 6
#define SOUTH_APPROACH 7
#define LIGHT_RIGHT 9
#define LIGHT_LEFT 10
#define BELL_RELAY 11

int northstate = 0;
int islandstate = 0;
int southstate = 0;
int lastnorthstate = 0;
int lastsouthstate = 0;
int lastislandstate = 0;

void setup() {
  pinMode(NORTH_APPROACH, INPUT_PULLUP);  //TRACK CIRCUIT ONE
  pinMode(ISLAND_CIRCUIT, INPUT_PULLUP);  //ISLAND APPROACH CIRCUIT
  pinMode(SOUTH_APPROACH, INPUT_PULLUP);  //TRACK CIRCUIT TWO
  pinMode(BELL_RELAY, OUTPUT);            //RR BELL COIL
  pinMode(LIGHT_LEFT, OUTPUT);            //LEFT FLASHING LIGHT
  pinMode(LIGHT_RIGHT, OUTPUT);           //RIGHT FLASHING LIGHT
  Serial.begin(9600);
}

void loop() {
  northstate = digitalRead(NORTH_APPROACH);
  islandstate = digitalRead(ISLAND_CIRCUIT);
  southstate = digitalRead(SOUTH_APPROACH);
  if(northstate != lastnorthstate || southstate != lastsouthstate || islandstate != lastislandstate)  {
    if(northstate = LOW && southstate = HIGH || northstate = HIGH && southstate = LOW){
      flash();
    if(northstate = LOW && islandstate  = LOW || southstate = LOW && islandstate  = LOW){
      flash();
    }else{
      stop();
    }
    lastnorthstate = northstate;
    lastislandstate = islandstate;
    lastsouthstate =southstate; 
  }
  delay(50);
}




void flash() {
  digitalWrite(LIGHT_LEFT, LOW && LIGHT_RIGHT, HIGH);
  digitalWrite(BELL_RELAY, LOW);
  delay(750);
  digitalWrite(LIGHT_LEFT, HIGH && LIGHT_RIGHT, LOW);
  digitalWrite(BELL_RELAY, LOW);
  delay(750);
}

void stop(){
  digitalWrite(LIGHT_HIGH, HIGH && LIGHT_RIGHT, HIGH);
  digitalWrite(BELL_RELAY, HIGH);
}

= for assignment, == for comparison. An if structure is comparison.

Look at the Notes and Warnings in the if reference (linked above).

Beware of accidentally using the single equal sign (e.g. if (x = 10) ). The single equal sign is the assignment operator, and sets x to 10 (puts the value 10 into the variable x). Instead use the double equal sign (e.g. if (x == 10) ), which is the comparison operator, and tests whether x is equal to 10 or not. The latter statement is only true if x equals 10, but the former statement will always be true.

If that does not fix the code, tell us what the code actually does and how that differs from what you want the code to do.

Ok. Looking at it now it makes sense with = vs ==. I’ll let you know if this helps by Sunday.

Inputted the fix but sadly, nothing happened because the compiler called my subroutines flash and stop said not in scope. I'm guessing it's a syntax error.

In terms of what the code is supposed to do.

At its simplest operation when either the north or south approach is activated from a totally empty crossing circuit, the crossing activates flashing the lights and ringing the bell until the train passes through the island circuit and on to the opposite approach circuit or backs off the island circuit back onto the circuit the train came in on only to reactivate when movement hits the island circuit once more and through onto the opposite approach.

...failed to post the new code.

Don't expect us to be able to accurately guess and backfit solutions to your original!

Don't worry, the internet has plenty of room for your latest.

TIA

a7

A cause of that can be missing or misplaced curly brackets. Use the IDE autoformat tool (ctrl-t or Tools, Auto format) to format your code. That may point out the missing brackets.

The compiler may not be properly generating the prototypes. Move the flash and stop functions above loop and try it again.

#define NORTH_APPROACH 5
#define ISLAND_CIRCUIT 6
#define SOUTH_APPROACH 7
#define LIGHT_RIGHT 9
#define LIGHT_LEFT 10
#define BELL_RELAY 11

int northstate = 0;
int islandstate = 0;
int southstate = 0;
int lastnorthstate = 0;
int lastsouthstate = 0;
int lastislandstate = 0;

void setup() {
  pinMode(NORTH_APPROACH, INPUT_PULLUP);  //TRACK CIRCUIT ONE
  pinMode(ISLAND_CIRCUIT, INPUT_PULLUP);  //ISLAND APPROACH CIRCUIT
  pinMode(SOUTH_APPROACH, INPUT_PULLUP);  //TRACK CIRCUIT TWO
  pinMode(BELL_RELAY, OUTPUT);            //RR BELL COIL
  pinMode(LIGHT_LEFT, OUTPUT);            //LEFT FLASHING LIGHT
  pinMode(LIGHT_RIGHT, OUTPUT);           //RIGHT FLASHING LIGHT
  Serial.begin(9600);
}

void flash() {
  digitalWrite(LIGHT_LEFT, LOW); 
  digitalWrite(LIGHT_RIGHT, HIGH);
  digitalWrite(BELL_RELAY, LOW);
  delay(750);
  digitalWrite(LIGHT_LEFT, HIGH); 
  digitalWrite(LIGHT_RIGHT, LOW);
  digitalWrite(BELL_RELAY, LOW);
  delay(750);
}

void stop(){
  digitalWrite(LIGHT_LEFT, HIGH);
  digitalWrite(LIGHT_RIGHT, HIGH);
  digitalWrite(BELL_RELAY, HIGH);
}

void loop() {
  northstate = digitalRead(NORTH_APPROACH);
  islandstate = digitalRead(ISLAND_CIRCUIT);
  southstate = digitalRead(SOUTH_APPROACH);
  if(northstate != lastnorthstate || southstate != lastsouthstate || islandstate != lastislandstate)  {
    if(northstate == LOW && southstate == HIGH || northstate == HIGH && southstate == LOW){
      flash();
    if(northstate = LOW && islandstate  == LOW || southstate == LOW && islandstate == LOW){
      flash();
    }else{
      stop();
    }
    lastnorthstate = northstate;
    lastislandstate = islandstate;
    lastsouthstate = southstate; 
  }
  delay(50);
  }
}
Sorry about that. I've got the == implemented along with moving the subroutines. Now when I complete the circuit for 5 alone. Nothing happens. With five in and adding six, it loops once and stops. Removing six with five still in will cause it to loop once and stop. With five and six in and adding 7 nothing happens. Removing 5 with 6 and 7 in, loop once and stop. Removing 5 and 6 while leaving 7 will cause it to loop but abruptly. Removing 7 with all others empty will cause it to stop.

What should happen is 5 or 7 start sequence, 6 continues the sequence and stops when the opposite is activated only after passing through 6 or if going from 6 back to the original side first activated.

The posted code compiles for me (Uno, Win 10, IDE 1.8.19)

There are warnings:

if(northstate = LOW && 

Line 55 still assignment, not ==.

Enable compile warnings in the IDE, go to File Preferences and check compile warnings then compile again to see the other warnings.


```
//THIS CODE IS DESIGNED TO REPLICATE A TRADITIONAL ISLAND APPROACH ISLAND RAILROAD CROSSING CIRCUIT THAT WILL BE USED FOR A 1/8 SCALE MODEL RAILROAD AND FUNCTION PROTOTYPICALLY TO THE REAL CIRCUIT
//

#define NORTH_APPROACH 5
#define ISLAND_CIRCUIT 6
#define SOUTH_APPROACH 7
#define LIGHT_RIGHT 9
#define LIGHT_LEFT 10
#define BELL_RELAY 11

int northstate = 0;
int islandstate = 0;
int southstate = 0;
int lastnorthstate = 0;
int lastsouthstate = 0;
int lastislandstate = 0;

void setup() {
  pinMode(NORTH_APPROACH, INPUT_PULLUP);  //TRACK CIRCUIT ONE
  pinMode(ISLAND_CIRCUIT, INPUT_PULLUP);  //ISLAND APPROACH CIRCUIT
  pinMode(SOUTH_APPROACH, INPUT_PULLUP);  //TRACK CIRCUIT TWO
  pinMode(BELL_RELAY, OUTPUT);            //RR BELL COIL
  pinMode(LIGHT_LEFT, OUTPUT);            //LEFT FLASHING LIGHT
  pinMode(LIGHT_RIGHT, OUTPUT);           //RIGHT FLASHING LIGHT
  Serial.begin(9600);
}

void loop() {
  digitalWrite(LIGHT_LEFT, HIGH);
  digitalWrite(LIGHT_RIGHT, HIGH);
  digitalWrite(BELL_RELAY, HIGH);
  northstate = digitalRead(NORTH_APPROACH);
  islandstate = digitalRead(ISLAND_CIRCUIT);
  southstate = digitalRead(SOUTH_APPROACH);
  if (northstate != lastnorthstate || southstate != lastsouthstate || islandstate != lastislandstate) {
    if (northstate == LOW && southstate == HIGH || northstate == HIGH && southstate == LOW) {
        flash();
      if (northstate == LOW && islandstate == LOW || southstate == LOW && islandstate == LOW) {
        flash();
      } else {
        stop();
      }
      lastnorthstate = northstate;
      lastislandstate = islandstate;
      lastsouthstate = southstate;
    }
    delay(50);
  }
}

void flash() {
  digitalWrite(LIGHT_LEFT, LOW);
  digitalWrite(LIGHT_RIGHT, HIGH);
  digitalWrite(BELL_RELAY, LOW);
  delay(750);
  digitalWrite(LIGHT_LEFT, HIGH);
  digitalWrite(LIGHT_RIGHT, LOW);
  digitalWrite(BELL_RELAY, LOW);
  delay(750);
}

void stop() {
  digitalWrite(LIGHT_LEFT, HIGH);
  digitalWrite(LIGHT_RIGHT, HIGH);
  digitalWrite(BELL_RELAY, HIGH);
}

```
The last missing == should be good now. The code is compiling and "running" now. Still not how it should, but the compiler is less angry.
/*This code is designed to replicate a traditional Island Approach Island Railroad Crossing Circut
that will be used for a 1/8 scale model railroad and function prototypically to the real circuit.
Hardware used is an Arduino Mega/Mega 2560 with a four channel relay shield where LOW=ON along 
with a 12V incadescent flush mount trailer lights and either an authentic 12V RR crossing bell 
or a SoundByte Crossing Bell speaker module. Track circuits are desinged to be 5V pullup signals but 
may require an inline voltage step-up/step-down device to amplify the signals. 
Track circuits are defined by insulating joins per the prototype.
*/

#define NORTH_APPROACH 5
#define ISLAND_CIRCUIT 6
#define SOUTH_APPROACH 7
#define LIGHT_RIGHT 10
#define LIGHT_LEFT 9
#define BELL_RELAY 11

void setup() {
  pinMode(NORTH_APPROACH, INPUT_PULLUP);  //Track circuit one. 60ft/39.5m long. Primary circuit the train activates 90% of the time.
  pinMode(ISLAND_CIRCUIT, INPUT_PULLUP);  //Island circuit. 30ft/9m long. Circuit travels through a #5 Right hand Turnout that diverges.
  pinMode(SOUTH_APPROACH, INPUT_PULLUP);  //Track circuit two. Same length as number one, but needs to be able to activate the crossing from the other direction.
  pinMode(BELL_RELAY, OUTPUT);            //RR Bell Coil/SoundByte Speaker.
  pinMode(LIGHT_LEFT, OUTPUT);            //Left Flashing Light.
  pinMode(LIGHT_RIGHT, OUTPUT);           //Right Flashing Light.
}
enum CROSSINGSTATES {
  ST_OFF,
  ST_APPROACH_N,
  ST_APPROACH_S,
  ST_ISLAND,
  ST_CLEARING_N,
  ST_CLEARING_S,
};

CROSSINGSTATES crossingState = ST_OFF;

void loop() {
  int north = digitalRead(NORTH_APPROACH);
  int island = digitalRead(ISLAND_CIRCUIT);
  int south = digitalRead(NORTH_APPROACH);
  int last = 0;     //Previous state case. 0=ST_OFF, 1=ST_APPROACH_N, 2=ST_APPROACH_S, 3=ST_ISLAND, 4=ST_CLEARING_N, 5=ST_CLEARING_S.
  int current = 0;  //Current state case. 0=ST_OFF, 1=ST_APPROACH_N, 2=ST_APPROACH_S, 3=ST_ISLAND, 4=ST_CLEARING_N, 5=ST_CLEARING_S.

  switch (crossingState) {
    case ST_OFF:
      crossingoff(north, island, south, last, current);
      break;
    case ST_APPROACH_N:
      appnorth(north, island, south, last, current);
      break;
    case ST_APPROACH_S:
      appsouth(north, island, south, last, current);
      break;
    case ST_ISLAND:
      crossingblocked(north, island, south, last, current);
      break;
    case ST_CLEARING_N:
      clearingnorth(north, island, south, last, current);
      break;
    case ST_CLEARING_S:
      clearingsouth(north, island, south, last, current);
      break;
  }
}

void crossingoff(int north, int island, int south, int last, int current) {
  digitalWrite(LIGHT_LEFT, HIGH);  //Code loop turns off all lights and bells until a meet break condition is satisfied.
  digitalWrite(LIGHT_RIGHT, HIGH);
  digitalWrite(BELL_RELAY, HIGH);
  if (north == LOW && island == HIGH && south == HIGH && current == 0) {  //If the north circuit activates first while the remaining two are empty. Start the light and bell sequence.
    current = 1;
    last = current;
    crossingState = ST_APPROACH_N;
  } else if (south == LOW && island == HIGH && south == HIGH && current == 0) {  //If the south circuit activates first while the remaining two are empty. Start the light and bell sequence.
    current = 2;
    last = current;
    crossingState = ST_APPROACH_S;
  }
}

void appnorth(int north, int island, int south, int last, int current) {
  digitalWrite(LIGHT_LEFT, LOW);  //Alternating flashing lights at 120 flashes per minute. Code block repeats until a meet break condition is satisfied.
  digitalWrite(LIGHT_RIGHT, HIGH);
  digitalWrite(BELL_RELAY, LOW);
  delay(500);
  digitalWrite(LIGHT_LEFT, HIGH);
  digitalWrite(LIGHT_RIGHT, LOW);
  digitalWrite(BELL_RELAY, LOW);
  delay(500);
  if (north == LOW && island == LOW && south == HIGH && last == 1) {  //Keep the light and bell sequence going if one of the approach circuits and the island circuit are activated.
    current = 3;
    last = current;
    crossingState = ST_ISLAND;
  } else if (north == LOW && island == LOW && south == LOW && last == 1) {  //Keep the light and bell sequence going if all of the circuits are activated.
    current = 3;
    last = current;
    crossingState = ST_ISLAND;
  } else if (north == HIGH && island == LOW && south == HIGH && last == 1) {  //Keep the light and bell sequence going if the island is activated even if the approaches aren't.
    current = 3;
    last = current;
    crossingState = ST_ISLAND;
  } else if (north == LOW && island == HIGH && south == LOW && last == 1) {  //Keep the light and bell sequence going if both approach circuits are activated even if the island isn't.
    current = 3;
    last = current;
    crossingState = ST_ISLAND;
  } else if (north == LOW && island == HIGH && south == LOW && last == 1) {  //Stop the light and bell sequence if the train leaves the approach circuit.
    current = 0;
    last = current;
    crossingState = ST_OFF;
  }
}

void appsouth(int north, int island, int south, int last, int current) {
  digitalWrite(LIGHT_LEFT, LOW);  //Alternating flashing lights at 120 flashes per minute. Code block repeats until a meet break condition is satisfied.
  digitalWrite(LIGHT_RIGHT, HIGH);
  digitalWrite(BELL_RELAY, LOW);
  delay(500);
  digitalWrite(LIGHT_LEFT, HIGH);
  digitalWrite(LIGHT_RIGHT, LOW);
  digitalWrite(BELL_RELAY, LOW);
  delay(500);
  if (north == LOW && island == LOW && south == HIGH && last == 2) {  //Keep the light and bell sequence going if one of the approach circuits and the island circuit are activated.
    current = 3;
    last = current;
    crossingState = ST_ISLAND;
  } else if (north == LOW && island == LOW && south == LOW && last == 2) {  //Keep the light and bell sequence going if all of the circuits are activated.
    current = 3;
    last = current;
    crossingState = ST_ISLAND;
  } else if (north == HIGH && island == LOW && south == HIGH && last == 2) {  //Keep the light and bell sequence going if the island is activated even if the approaches aren't.
    current = 3;
    last = current;
    crossingState = ST_ISLAND;
  } else if (north == LOW && island == HIGH && south == LOW && last == 2) {  //Keep the light and bell sequence going if both approach circuits are activated even if the island isn't.
    current = 3;
    last = current;
    crossingState = ST_ISLAND;
  } else if (north == LOW && island == HIGH && south == LOW && last ==2) {  //Stop the light and bell sequence if the train leaves the approach circuit.
    current = 0;
    last = current;
    crossingState = ST_OFF;
  }
}

void crossingblocked(int north, int island, int south, int last, int current) {
  digitalWrite(LIGHT_LEFT, LOW);  //Alternating flashing lights at 120 flashes per minute. Code block repeats until a meet break condition is satisfied.
  digitalWrite(LIGHT_RIGHT, HIGH);
  digitalWrite(BELL_RELAY, LOW);
  delay(500);
  digitalWrite(LIGHT_LEFT, HIGH);
  digitalWrite(LIGHT_RIGHT, LOW);
  digitalWrite(BELL_RELAY, LOW);
  delay(500);
  if (north == LOW && south == HIGH && island == HIGH && last == 3) {  //If the train has reached the island and either crosses over it completely or backs off, stop the bell and light sequence even if the train is on an approach circuit.
    current = 4;
    last = current;
    crossingState = ST_CLEARING_N;
  } else if (south == LOW && island == HIGH && north == HIGH && last == 3) {  //If the train has reached the island and either crosses over it completely or backs off, stop the bell and light sequence even if the train is on an approach circuit.
    current = 5;
    last = current;
    crossingState = ST_CLEARING_S;
  }
}

void clearingnorth(int north, int island, int south, int last, int current) {
  digitalWrite(LIGHT_LEFT, HIGH);  //Code loop turns off all lights and bells until a meet break condition is satisfied.
  digitalWrite(LIGHT_RIGHT, HIGH);
  digitalWrite(BELL_RELAY, HIGH);
  if (north == HIGH && island == HIGH && south == HIGH && last == 4) {  //If all of the circuits are empty, return to the default state.
    current = 0;
    last = current;
    crossingState = ST_OFF;
  } else if (north == LOW && island == HIGH && south == LOW && last == 4) {  //Reactivate the light and bell sequence if both approach circuits are activated even if the island isn't.
    current = 3;
    last = current;
    crossingState = ST_ISLAND;
  } else if (north == LOW && island == LOW && south == LOW && last == 4) {  //Reactivate the light and bell sequence if all of the circuits are activated.
    current = 3;
    last = current;
    crossingState = ST_ISLAND;
  } else if (north == LOW && island == LOW && south == HIGH && last == 4) {  //Reactivate the light and bell sequence if one of the approach circuits and the island circuit are activated.
    current = 3;
    last = current;
    crossingState = ST_ISLAND;
  } else if (north == HIGH && island == LOW && south == LOW && last == 4) {  //Reactivate the light and bell sequence if one of the approach circuits and the island circuit are activated.
    current = 3;
    last = current;
    crossingState = ST_ISLAND;
  } else if (north == HIGH && island == LOW && south == HIGH && last == 4) {  //Reactivate the light and bell sequence if the island is activated even if the approaches aren't.
    current = 3;
    last = current;
    crossingState = ST_ISLAND;
  }
}

void clearingsouth(int north, int island, int south, int last, int current) {
  digitalWrite(LIGHT_LEFT, HIGH);  //Code loop turns off all lights and bells until a meet break condition is satisfied.
  digitalWrite(LIGHT_RIGHT, HIGH);
  digitalWrite(BELL_RELAY, HIGH);
  if (north == HIGH && island == HIGH && south == HIGH && last == 5) {  //If all of the circuits are empty, return to the default state.
    current = 0;
    last = current;
    crossingState = ST_OFF;
  } else if (north == LOW && island == HIGH && south == LOW && last == 5) {  //Reactivate the light and bell sequence if both approach circuits are activated even if the island isn't.
    current = 3;
    last = current;
    crossingState = ST_ISLAND;
  } else if (north == LOW && island == LOW && south == LOW && last == 5) {  //Reactivate the light and bell sequence if all of the circuits are activated.
    current = 3;
    last = current;
    crossingState = ST_ISLAND;
  } else if (north == LOW && island == LOW && south == HIGH && last == 5) {  //Reactivate the light and bell sequence if one of the approach circuits and the island circuit are activated.
    current = 3;
    last = current;
    crossingState = ST_ISLAND;
  } else if (north == HIGH && island == LOW && south == LOW && last == 5) {  //Reactivate the light and bell sequence if one of the approach circuits and the island circuit are activated.
    current = 3;
    last = current;
    crossingState = ST_ISLAND;
  } else if (north == HIGH && island == LOW && south == HIGH && last == 5) {  //Reactivate the light and bell sequence if the island is activated even if the approaches aren't.
    current = 3;
    last = current;
    crossingState = ST_ISLAND;
  }
}

If anyone would still like to help me, I've rewrote my code using a state switch case format from the ground up taking in every piece of feedback I could along with formatting it to be cleaner. Currently my code gets stuck repeating ST_APPROACH_N after activating it from pin5 and won't progress on to any of the other states. Additionally, the program doesn't jump to ST_APPROACH_S when activating it from pin7.

The state flow is supposed to start at ST_OFF, go to either ST_APPROACH_N or ST_APPROACH_S depending on which track circuit is activated first. Followed by jumping to ST_OFF if the train backs off the approach circuits before reaching the island or jumps to ST_ISLAND while the train is on the island circuit. Once here the program should jump to ST_CLEARING_N or ST_CLEARING_S if the train crosses over the island to the opposite circuit it arrived on or backs up onto the circuit it arrived on. Only when the train is clear of all circuits should the program jump back to ST_OFF and reset.

Sorry if I haven't responded in a while. I had to put the project on hold to focus on some life events that have come about. I feel like I've angered some of you when I failed to post my original modification and I apologize if I did. I never meant to do that, and it was an honest mistake.

Haha, it's your project and you get to decide how and when to make it go forward, and whether or not to ask for help.

Even as we care or don't, and may or may not respond. Right away or ever. So no worries.

And I seem to be the one who asked for the new code, I was by no means angry, just perhaps frustrated at that moment. You'd be surprised how much difference there can be when someone asserts "I made some changes…" to what those changes were actually, compared to what anyone might have been suggesting. Just forum etiquette- new code, post the new sketch.

I look forward to being able to examine your code, which is not now.

I am totally unable to figure out what this is supposed to do, and while I appreciate your many words on the matter, there's a reason some will call it "word salad" and move on.

Since you are using a state machine approach, I wonder if at any time you have considered sharing a state diagram, which is a better way to unambiguous communicate the desired functionality of the algorithm.

Or maybe you actually got this far without ever having drawn such a thing.

If you have not, and don't know how, I can suggest you google

  example state flow diagram

and select "images" and poke around a bit. It is not a flowchart, but something like this, what I found gooogling exactly what I wrote above:

Where the bubbles are states, and the arrows reflect responses to inputs or calculations based on inputs plus the current state which require a change to a new state.

Meanwhile, I google to learn more about

Island Approach Island

in the context of RR systems.

The weather here is scheduled to be spot perfect for the beach, so the lab may be missing me for some time, like I implied. :wink: But all will benefit from a graphical expression as I ask you to share or make and then.

a7

1 Like

Sounds good. I’ll try to chop up the word salad and get you a flow state chart that’s easier to digest.

State_Diagram_Crossing_V1.pdf (67.4 KB)
State_Diagram_Crossing_V2.pdf (77.4 KB)
How Are Railroad Crossings Activated? | Worldwide Rails

How Railroad Crossing Signals Work - YouTube 13:00 mark
Railroad Signaling Explained: Crossings - YouTube 17:00 mark

Hope the Memorial Day beach weekend was enjoyable. I've got the word salad chopped up into two state diagrams. V2 is slightly more ambitious but I think if we can get V1 working, I'll be perfectly happy. V2 includes a timeout and reactivation sequence using a button. I've also additionally included an article and two YouTube videos hopefully explaining more about more about the RR Approach Island Approach Circuit setup. I'll keep trying to get my code hopefully working.

Thanks for the video. Had to laugh after some point when the guy said something like well that's that simplified explanation.

I'll look closer at your state diagrams. At the glance I've been able to give them, they are useful but perhaps not ready to code against.

Mostly there are yet ambiguities and perhaps too much under assumption. I'll try to meet you halfway, but I can't have time to become a subject matter expert. I can say if there were two of me it looks like a fascinating set of issues and solutions to them.

On the meantime, if I didn't mention or you haven't added to your reading pile looking into the IPO model, here's an abstract view

IPO model.

It dovetails nicely with finite state machines.

Look at other things that use FSMs to see more what might constitute a "state". I'll try to get the Umbrella Academy to think with me later at the beach. A hot day on tap.

Is it fair to say that the approaches and crossing signals are basically switches Yes or No there is a train on top of a point? So active means yes, there is a train, albeit moving or not, stop some kind of sensor?

a7

@jensenjosht Is the code of post#11 your current code? If not, please update us.
Thanks

#11 Is currently the most recent version I have both saved off and uploaded. Also yes the best way to look at the track circuit are simple toggle switches. Each section is blocked off using insulated joints on the rails. Power is sent down on rail and returned down the other and the switch is closed when the steel/Fe wheel forces the power to jump to the return.

needs to be global.

If you post code that doesn't compile, it saves time if you tell us that, and post the error message(s)

Working on trying to fix the int globally. The only noticeable error I get when compiling the code in its current state is an unused int warning. Need to do some more reading into the IPO model. Hope to have a new code posted soon.

Please post code (all of it), not pictures of code.
I can't compile or edit pictures.

The code in reply 11 has "last" local to "loop()", so is not in scope in other functions, so cannot compile.

1 Like