Auto tennis ball shooter code help

The machine has a very odd behavior of instead of waiting for the VEX limit switch (http://www.vexrobotics.com/276-2174.html) to give the HIGH signal and spin the motors full forward for 5 seconds, it simply spins full forward immediately and if the limit switch is tripped for 5-6 seconds the motors stop till the switch is released. Anyone know whats wrong????

#include <Servo.h>

Servo Victor;


const int LimitSwitch = 2;


void setup()  // This runs once, at startup
{
  pinMode( LimitSwitch, INPUT);
  Victor.attach(9);
}


void loop()  // This loop runs over and over
{

  Victor.writeMicroseconds(1500); // Turn the shooter off


  if( digitalRead(LimitSwitch) == HIGH)  // If the limit switch is pressed
  {
     Victor.writeMicroseconds(2000); // Turn the shooter on
     delay (5000); // Timer for ball to shoot 
  }


}

Sounds like your limit switch might be Active Low: It signals LOW when pushed and HIGH when not pushed.

I'll give that a try later tonight. If not, what else could it be?

The description in the link you supplied says it's Active LOW:

"Switch Type: SPDT microswitch, configured for SPST Normally Open behavior. Behavior: When the limit switch is not being pushed in, the sensor maintains a digital HIGH signal on its sensor port. This High signal is coming from the Microcontroller. When an external force (like a collision or being pressed up against a wall) pushes the switch in, it changes its signal to a digital LOW until the limit switch is released. An unpressed switch is indistinguishable from an open port."

This also indicates you need a pull-up resistor. Either mount one externally or use the internal one by changing:

  pinMode( LimitSwitch, INPUT);

to

  pinMode( LimitSwitch, INPUT_PULLUP);

If you don't have a pull-up resistor you may get random LOW indications when the switch is not pressed.