I cannot get the last code set to execute.

I have this code for a model railroad project that is working for the most part, but, the last "while" instruction does not execute. I know for a fact the signal to the pins are there, but, it will not execute the "while" statement at all.

I do NOT need to use millis, as when the signal is supposed to be YELLOW, it stays Green... and it is supposed to run the "while" command line as long as the input is TRUE(HIGH). It does not execute al all.

The only signal that should matter, is the nextbloxkFullState, which should tell the controller to run the YELLOW routine. It doesn't even see it... I have checked the signals, they are proper, and I have output to another LED from this, and it does NOT respond to the input. I KNOW the signals are there, I am getting frustrated, and thought maybe someone could see the problem, that has GOT to be a simple one!!! I KNOW the inputs and outputs are working... I tested each one individually with a short program for each. It seems the last "while" statement is not seeing and executing the command.

the first 2 "while" statements work PERFECTLY!!! All I have to do is get the YELLOW output to work.

Thanks in advance for your help folks!!

Here is the code:

// constants won’t change. They’re used here to 
// set pin numbers:

const int nextblockFull = 7;      // Next block full (input)
const int blockDirection = 6;     // LOW is inbound, HIGH is Outbound (input)
const int blockFull = 5;          // block is full (Output)
const int todPin = 4;             // the number of the Occupancy pin (input)
const int ledPin = 3;             // the number of the LED pin (Output)

// variables will change:


int todState = 0;
int blockDirectionState = 0;
int nextblockFullState = 0;
int blockFullState = 0;



void setup() {
 
   
 pinMode(blockFull, OUTPUT);       // initialize "block full" signal pin to PREVIOUS block Signal. HIGH = Signal is YELLOW
                                   // telling the previous block signal that it is clear to turn GREEN.

 
 
 pinMode(blockDirection, INPUT);   // initialize Block Traffic Direction input
                                   // if signal is HIGH, then Traffic is set for INBOUND direction. Keeping it RED.
                                   // if signal is LOW, then traffic is routed in the NORMAL direction ie. OUTBOUND

 
 
 pinMode(nextblockFull, INPUT);    // initialize Next block full signal INPUT from next block signal 
                                   // This INPUT is used to detect if the next Block Signal is RED.
                                   
 
 
 
 pinMode(ledPin, OUTPUT);          // initialize the LED pin as an output:
                                   // This is the signal head. It is a R/G bi directional LED.
                                   // This OUTPUT will be using PWM, as to generate the R-Y-G block signal

 
 
 pinMode(todPin, INPUT);           // initialize the UV pin as an input:
                                   // This INPUT tells the controller if the block is occupied, if this block is
                                   // occupied, the signal is HIGH, keeping the "OCCUPIED BLOCK", in the RED


  
}
void loop(){
 
 // read the Block direction state. HIGH = "Inbound", LOW = "Outbound" Traffic
 // This will keep the block from going "bi-directional" and head in to inbound traffic

 blockDirectionState = digitalRead(blockDirection);              // check for signal. if it is HIGH, the blockDirection is Outbound
                                                                 // If input is LOW, Block Traffic Direction is Inbound, and must stay RED until
                                                                 // until traffic direction switches to Outbound
                                                                 
   todState = digitalRead(todPin);                                 // read todState                                         


 while (blockDirectionState == HIGH) {                             // check block direction. if traffic direction is inbound, callRedSignal() to make RED 

        digitalWrite(ledPin, HIGH);                                // make signal LED RED
        digitalRead(blockDirectionState);
        return;    
 }   

 digitalWrite(ledPin, LOW);
 

 while (todState == HIGH){                                         // Detecting block full state, sets block signal to RED, sets blockFull HIGH
                                                                   // Stays "RED" as long as train is detected
     digitalWrite(ledPin, HIGH);
     digitalWrite(blockFull, HIGH);
     digitalRead(todState);
     return;

  }

 if (digitalRead(todState == LOW)){                                // when train is not detected, reset the Signal to GREEN

   digitalWrite(blockFull, LOW);                                   // return blockFull to LOW to tell the block is empty
   
 }

 nextblockFullState = (digitalRead, nextblockFull);                // check nextblockFullState
 todState = (digitalRead, todPin);                                 // check todState for LOW

   
    while (nextblockFullState == HIGH){                            // if the nextblockFullState is "HIGH", then executeflash LED to make it YELLOW color
     
       digitalWrite(ledPin, HIGH);
       delay(5);
       digitalWrite(ledPin, LOW);
       delay(18);
       return;
     }
       
 }

Please read the forum guide, then modify your post above and correct it.

These lines are nonsense. They are legal C and compile, but they don't do what you want. You use digitalRead() correctly in other places, what happened here?

  nextblockFullState = (digitalRead, nextblockFull);
  todState = (digitalRead, todPin);

Your while() loops have return instructions in them. Do you know what return does?

  while (nextblockFullState == HIGH){
      
        digitalWrite(ledPin, HIGH);
        delay(5);
        digitalWrite(ledPin, LOW);
        delay(18);
        return;
      }

I don't see any attempt to use Serial.println() to verify your claims!

Paul

I put the return in it, as a test. No matter what I do this while statement does not execute. The other 2 while statements function as stated. This is the only problem I am having. The other part of the source code works as it is supposed to. I am a new learner in software. The HARDWARE i know very well.
I just cannot get the last while code to execute.

// constants won’t change. They’re used here to 
// set pin numbers:

const int nextblockFull = 7;      // Next block full (input)
const int blockDirection = 6;     // LOW is inbound, HIGH is Outbound (input)
const int blockFull = 5;          // block is full (Output)
const int todPin = 4;             // the number of the Occupancy pin (input)
const int ledPin = 3;             // the number of the LED pin (Output)

// variables will change:


int todState = 0;
int blockDirectionState = 0;
int nextblockFullState = 0;
int blockFullState = 0;



void setup() {

  
  Serial.begin (115200);  // initialize serial comms at 115200 baud
  //  ... other setup here
  
    
  pinMode(blockFull, OUTPUT);       // initialize "block full" signal pin to PREVIOUS block Signal. HIGH = Signal is YELLOW
                                    // telling the previous block signal that it is clear to turn GREEN.

  
  
  pinMode(blockDirection, INPUT);   // initialize Block Traffic Direction input
                                    // if signal is HIGH, then Traffic is set for INBOUND direction. Keeping it RED.
                                    // if signal is LOW, then traffic is routed in the NORMAL direction ie. OUTBOUND

  
  
  pinMode(nextblockFull, INPUT);    // initialize Next block full signal INPUT from next block signal 
                                    // This INPUT is used to detect if the next Block Signal is RED.
                                    
  
  
  
  pinMode(ledPin, OUTPUT);          // initialize the LED pin as an output:
                                    // This is the signal head. It is a R/G bi directional LED.
                                    // This OUTPUT will be using PWM, as to generate the R-Y-G block signal

  
  
  pinMode(todPin, INPUT);           // initialize the UV pin as an input:
                                    // This INPUT tells the controller if the block is occupied, if this block is
                                    // occupied, the signal is HIGH, keeping the "OCCUPIED BLOCK", in the RED


   
}
void loop(){
  
  // read the Block direction state. HIGH = "Inbound", LOW = "Outbound" Traffic
  // This will keep the block from going "bi-directional" and head in to inbound traffic

  blockDirectionState = digitalRead(blockDirection);              // check for signal. if it is HIGH, the blockDirection is Outbound
                                                                  // If input is LOW, Block Traffic Direction is Inbound, and must stay RED until
                                                                  // until traffic direction switches to Outbound
                                                                  
    todState = digitalRead(todPin);                                 // read todState                                         


  while (blockDirectionState == HIGH) {                             // check block direction. if traffic direction is inbound, callRedSignal() to make RED 

         digitalWrite(ledPin, HIGH);                                // make signal LED RED
         digitalRead(blockDirectionState);
         return;    
  }   

  digitalWrite(ledPin, LOW);
  

  while (todState == HIGH){                                         // Detecting block full state, sets block signal to RED, sets blockFull HIGH
                                                                    // Stays "RED" as long as train is detected
      digitalWrite(ledPin, HIGH);
      digitalWrite(blockFull, HIGH);
      digitalRead(todState);
      return;

   }

  if (digitalRead(todState == LOW)){                                // when train is not detected, reset the Signal to GREEN

    digitalWrite(blockFull, LOW);                                   // return blockFull to LOW to tell the block is empty
    
  }

  nextblockFullState = (digitalRead, nextblockFull);                // check nextblockFullState
  todState = (digitalRead, todPin);                                 // check todState for LOW

    
     while (nextblockFullState == HIGH){                            // if the nextblockFullState is "HIGH", then executeflash LED to make it YELLOW color
      
        digitalWrite(blockFull, HIGH);
        delay(5);
        digitalWrite(blockFull, LOW);
        delay(18);
        return;
      }
        
  }

Thank you for using code tags in your last post. But there are still no code tags in your earlier post, which I asked you to modify. No one wants to keep having to scroll through that every time to see the latest post.

I can't see anything different in your code from #4. The same mistakes are still there. What did you change? If it's the same, why did you post it again?

I do not know how to use serial begin, or the other things like that. I have not read that far, and at this point, I do not need too! I am beginning to feel as if i am being chided, when all I asked for was a little help. Is it THAT difficult, to offer some GUIDANCE, without being so condescending? I have a few lines added for MY TROUBLESHOOTING, maybe it isn't like YOU would do. Everyone is different, so please, make your comments as a TEACHER, and NOT as a chiding. THAT is how it was taken.... I am sure you are a smart man, Paul, but, you really need to work on your communications skills a bit. Being a genius programmer, is a good thing, but, making me feel like I am doing something dumb, and a project that does not interest most, is not the way to be.... I took insult, and I am NOT easily offended. Lets just help people like me who are learning, and do it in a manner that is NOT condescending to those of us who are not a "BLESSED" as you are...

If some code does not do anything, and does not need to be there, just ask, and say it in a manner that does NOT belittle ANYONE!! Telling me the lines are "JUNK", is a NASTY, and condescending way to treat someone. I would appreciate a response that was LEARNING, and HELPFUL!!!

THANK YOU for your time...

These lines don't look good to me:

nextblockFullState = (digitalRead, nextblockFull);
todState = (digitalRead, todPin);

Did you mean

nextblockFullState = digitalRead(nextblockFull);
todState = digitalRead(todPin);

??

Edit: PaulRB already wrote that at 9.03pm. Didn't you read that?

I assumed I had this right. I will try this code line and see. Thank you!
I will be back shortly...

Retired_Phart:
I do not know how to use serial begin, or the other things like that. I have not read that far, and at this point, I do not need too!

But you do! It's the first thing you need for debugging your code.

void setup()
{
  Serial.begin(9600);
  Serial.println("Hello, world.");
}

THANKS ERIK!!! THAT CURED THE PROBLEM!!!
I KNEW it had to be something I mis-coded, and put there. I guess I needed to step away and look at it again, and you picked it out immediately....

GREAT JOB!!!! THANKS AGAIN!!!

Taz...

I am beginning to feel as if i am being chided, when all I asked for was a little help. Is it THAT difficult, to offer some GUIDANCE, without being so condescending?

You deserve to be chided. At the top of every forum section is a post titled "how to use this forum". Everyone should read this before using the forum. We are used to immature new forum members choosing to ignore it, but a mature new forum member like yourself should know better. Yes, it often is difficult to help new members who don't follow the guide, that's why we have a guide. For example, the forum software can easily mangle and corrupt code that's not inside code tags, making it difficult to read and even introducing errors into the code.

Anyway, thanks for putting the code tags into your original post. +1 Karma.