Go Down

Topic: Using timers to stay in a loop. (Read 791 times) previous topic - next topic

Jason2548

They are servos.  They are servos running mechanical switches on a train track

Jason2548

#6
Jan 30, 2013, 09:16 pm Last Edit: Jan 30, 2013, 09:19 pm by Jason2548 Reason: 1
With that.  What I have is sensors that are below a train track that let me know when trains are getting closer to a switch.  Then depending on what sensors are high determins what happens with the switch and lights.  Right now I would like it so that the train enters a track and waits to see if another train approaches if not then it moves onto the main track and continues on its merry way.  If I can get the timer right then I could use it in other junctions of the train tracks.

Also can you make it so that it reads all the digital inputs easier without writing a paragraph.

Arrch

Code: [Select]

void loop() {
  ...
fgo();
}
//-------------------------------------------------------
void fgo(){
...
loop();
}


What you have here is recursion and I'm certain that's not what you are looking to do. I'm guessing that you see these function calls as more of a "go to this part of the code", which simply isn't the case.

If you want to stay within a certain portion of code until a condition is met, you need a while loop:

Code: [Select]
while (condition)
{
  // Execute code
}

Jason2548

I understand, I thought about that.  How can I stay in that condition under a certain amount of time.  If that limit is reached then the code needs to move on to the next part.

Nick Gammon


Go Up