What am I doing wrong>?

I've tried everything. The last thing I did was add int to the beginning of everything. What am I doing wrong?

attachInterrupt(2, speedA, RISING);                   //When Interrupt 2 goes from LOW to HIGH the program will jump to the counter start/stop ISR for Train A
attachInterrupt(3, speedB, RISING);                   //When Interrupt 2 goes from LOW to HIGH the program will jump to the counter start/stop ISR for Train B
void speedA() {
if (valA == 0) {
     int startA = millis(); 
     int valA = 1;
  }
else {
     stopA=millis(); 
     int valA = 0;
     int timeA = stopA-startA;
}
}
//-Coutner Start/Stop for Train B
void speedB() {
if (valA == 0) {
     int startB = millis(); 
     int valB = 1;
  }
else {
     int stopB = millis(); 
     int valB = 0;
     int timeB = stopB-startB;
}  
}

The last thing I did was add int to the beginning of everything

Whilst that may do wonders for making things compile, it doesn't half screw things up when it comes to scope.

Your indenting hurts my eyes. Please use the auto-format tool in the IDE if all else fails.

And please, scrap the cutesy retro-70s ASCII art -it's a waste of bandwidth.

(sp. "collision")

And please, scrap the cutesy retro-70s ASCII art -it's a waste of bandwidth.

I've had to download it now. Teddy bears?

You have a bunch of issues here, but you didn't post the entire sketch so its hard to know for sure.

valA in the the speedA ISR is declared with very limited scope. If that code compiles, then you must also have another valA somewhere else, so the valA used in speedB is a different one than the valA used in speedA. If you do this:

int valA = 12;
// some code here

{
  int valA = 0; // this valA hides the prior valA and is different

  // more stuff
}

// When we get here, valA still == 12

Also, if you use global vars in an interrupt service routine, they need to be declared volatile. If not, their value can magically change.

attachInterrupt(2, speedA, RISING);                   //When Interrupt 2 goes from LOW to HIGH the program will jump to the counter start/stop ISR for Train A
attachInterrupt(3, speedB, RISING);                   //When Interrupt 2 goes from LOW to HIGH the program will jump to the counter start/stop ISR for Train B

What board are you using? The first argument is the interrupt number, not the pin that the interrupt is triggered by.

My first mistake was the teddy bears. Thank you for smacking me in the face. I deserve it. I also removed some of the wasted bandwidth at the top but I couldn't remove it all since the project that I'm working on requires a lot of things for a title and what not. As far as indenting, I tried the auto format but it only made things worse. I apologize for the indenting. This is literally the first major program I've ever written. Also thanks for the spelling correction. Now, I am using the Mega2560 and I do understand that those are the interrupt numbers. Interrupts 2 & 3 should be at pins 21 and 20 respectively. I was in fact probing pins 20 and 21 with 5v to try and trigger the interrupts but I had no success. I tried to add volatile to the ones I believed needed to be declared as so. Also, the valA was supposed to be a valB. All the things I have discussed have been fixed. The entire sketch is attached below.

Thank you so much for the help guys!

These:

attachInterrupt(0, reset, RISING);                                             //When Interrupt 0 goes from LOW to HIGH the program will jump to the reset ISR
attachInterrupt(2, speedA, RISING);                   //When Interrupt 2 goes from LOW to HIGH the program will jump to the counter start/stop ISR for Train A
attachInterrupt(3, speedB, RISING);                   //When Interrupt 2 goes from LOW to HIGH the program will jump to the counter start/stop ISR for Train B

and these:

     delay(1000);
     delay(1000);
     delay(1000);
     delay(1000);

(and lots of others) just do not go together in the same program.

void speedB()
{
  if (valB == 0)
  {
     int startB = millis(); 
     int valB = 1;
  }
  else
  {
     int stopB = millis(); 
     int valB = 0;
     int timeB = stopB-startB;
  }  
}

So, when this interrupt routine does fire, you test the state of a global variable, valB, which you initialized to 0. If it is 0, you create two new variables, startB and valB as ints (startB should be unsigned long). The block ends, and startB and valB, being local variables, are discarded and the values lost. If the global valB value is not 0, you create 3 local variables, two of which have incorrect types, which go out of scope before the function ends.

The end result is that you ISR accomplished nothing.

Back to the drawing board.

What an interrupt should be doing is the minimum amount of work to deal with the event, passing the heavy lifting back to the main loop. Often this means the interrupt alters a few global volatile variables (and optionally talks to the device that provoked the interrupt to keep it happy and re-enable the interrupt).

For instance if you want to determine the time a signal went HIGH, the interrupt routine just has to read a timer register and store it in a variable.

Okay, so I made startA, startB, stopA, stopB all unsigned long. Removed delays which I don’t understand why…

I’m not trying to create local variables there. I’m trying to change the global values.

The global valB starts at 0. When the interrupt is triggered, the ISR looks at that value. If it is zero, it stores the current timer count into startB. It then makes valB 1. Next time the interrupt is triggered, it will see valB is not 0 and will then store that current timer count into stopB. It will then reset valB and do a simple calculation to change the value of timeB which is originally set to be 0 but will now be some value. This value will change every time this sequence occurs.

This is what I was trying to accomplish.

Serial.print() in an ISR is not a good idea. Get rid of them.

So, what problem(s), if any, are you having now?

To be honest, I'm having trouble getting the interrupt to trigger. I uploaded the button example program to my arduino and it works perfectly fine. Button down, led lights up, button not pushed, led is off. But when I have that same circuit hooked up to pin 20 or 21 and I load my new program, attached below, it doesn't do anything. I feel like the ISR isn't being triggered.

const int tiedis = 1.125;         //Distance between 5 ties is 1.125 inches

Are we having trouble with the concept of an int? 1.125 is NOT an int.

Your ISRs, speedA and speedB, could possibly fire hundreds of times before loop() gets an opportunity to do anything.

Exactly what is connected to pins 20 and 21?

Dump all the code in the ISRs now. Just toggle an LED, with external resistor, when the ISR files. Watch the LEDs as whatever is connected to pin 20 generates the interrupt signal. Each time that happens, the LED should toggle.

Get it working for one ISR/pin at a time.

Great Idea. Turns out those interrupts suck! Check out the new program. I changed the interrupts to 0 and 1 meaning pins 2 and 3 and success! I can now officially take and display timing between two 5v pulses.

Edit - I improved the program to count between every pulse instead of every two pulses like it was doing. So instead of a start/stop it always records the stop time, calculates, stores that stop time as the next start time, and then waits for the next pulse. Awesome! Finally getting somewhere! (: