Unreliable code - Using Serial.print to debug fixes problem

It was hard to pick a proper subject as there is a little to say.

The program below is going to control shifting on a small vehicle via switches. The button push will cause the signal to stay HIGH on pin 5 only or pin 5 and pin 3. I decided to debug the program by adding Serial.print to key locations so I could follow the logic. And here is the problem, with Serial.begin enabled the program works perfectly with no peculiar behavior. If I comment it out, like it is below, the program is very buggy and unreliable. This is the first program I wrote besides playing with simple LED's so maybe someone more experienced can speculate how the Serial.print may affect the code so I may try and fix it.

In essence Serial.begin disabled means code is unreliable, Serial.begin enabled means code works perfectly with extensive testing.

Thank you for you're time!

unsigned long downshiftDuration=300; //Time spent downshifting
unsigned long downshiftDeadTime=400; //Dead time after downshifting before able to shift again

unsigned long upshiftCutDelay=100; //delay before beginning cutting engine power when upshifting
unsigned long upshiftDelay=0; //delay before beginning applying CO2 when upshifting

unsigned long upshiftCutDuration=400; //time spent cutting engine power when upshifting
unsigned long upshiftDuration=500; //time spent applying CO2 when upshifting

unsigned long upshiftDeadTime=250; //Dead time after both cutting power and applying CO2 are finished

unsigned long debounce_timer=0; //Debounce timer and booleans for logic
unsigned long debounce_time=20;
boolean debounce_on=false;
boolean debounce_off=false;

boolean engineCut=false;     //Logic to determine up shifting state
boolean engineUpshift=false;

int eventState='0';
unsigned long triggerTime=0; 
unsigned long longestShiftTime=0;

int relay_upshift=3;
int relay_downshift=7;

int engine_signal=5;

int right_paddle=2;
int left_paddle=6;

int debounce_right=0;
int debounce_left=0;


void setup()
{
  pinMode(relay_upshift, OUTPUT);
  pinMode(engine_signal, OUTPUT);
  pinMode(right_paddle, INPUT);
  pinMode(left_paddle, INPUT);
  pinMode(relay_downshift, OUTPUT);
  //Serial.begin (9600);
}

void loop()
{
  //event
  switch(eventState)
  {
  case '0': //waiting for button press
    Serial.println("0-0");
    Serial.println(digitalRead(right_paddle));

    if (digitalRead(right_paddle)==HIGH && (debounce_on==false))
    {
      Serial.println("debounce set right\n");
      debounce_on=true;
      debounce_timer=millis();
    }

    else if (digitalRead(left_paddle)==HIGH && (debounce_on==false))
    {
      Serial.println("debounce set left");
      debounce_on=true;
      debounce_time=millis();
    } 
    else
    {
      if (digitalRead(right_paddle)==HIGH && (millis() >= (debounce_timer + debounce_time)))
      {
        triggerTime=millis(); //get start time
        eventState='1';
        longestShiftTime = max(upshiftCutDelay + upshiftCutDuration, upshiftDelay + upshiftDuration);
        engineCut=false;
        engineUpshift=false;
      }

      else if (digitalRead(left_paddle)==HIGH && (millis() >= (debounce_timer + debounce_time)))
      {
        Serial.print("4\n");
        triggerTime=millis();
        eventState='3';
        digitalWrite(relay_downshift,HIGH);
      }
    }
    break;

  case '1': //run upshift timing logic
    //Cutting engine power
    Serial.print("case 1\n");
    if (engineCut == false)
    {
      Serial.print("5\n");
      if (millis() >= triggerTime + upshiftCutDelay)
      {
        Serial.print("engine signal\n");
        //begin cutting engine power
        engineCut=true;
        digitalWrite(engine_signal,HIGH);
      }   
    }
    else 
    {
      Serial.print("6\n");
      if (millis() >= (triggerTime + upshiftCutDelay + upshiftCutDuration))
      {
        //stop cutting engine power
        digitalWrite(engine_signal,LOW); 
      }
    }
    Serial.print("7\n");
    //Applying CO2 shifting
    if (engineUpshift == false)
    {
      Serial.print("8\n");
      if (millis() >= triggerTime + upshiftDelay)
      {
        Serial.print("9\n");
        //begin applying CO2
        engineUpshift=true;
        digitalWrite(relay_upshift,HIGH);
      }   
    }
    else
    {
      Serial.print("10\n");
      if (millis() >= triggerTime + upshiftDelay + upshiftDuration)
      {
        Serial.print("11\n");
        //stop applying CO2
        digitalWrite(relay_upshift,LOW); 
      }
    }
    if (millis() >= triggerTime + longestShiftTime)
    {
      Serial.print("12\n");
      //upshifting + dead time has elapsed
      eventState='2';
      triggerTime=millis();
    }
    break;

  case '2': //waiting for dead time after end of button press
    //and wait for button to be unpressed before alowing state to be reset to 0

    if (digitalRead(right_paddle)==LOW && (debounce_off==false))
    {
      debounce_off=true;
      debounce_timer=millis();
    }

    else if (digitalRead(right_paddle)==LOW && (millis() >= debounce_timer + debounce_time))

      if (millis() >= (triggerTime + upshiftDeadTime) && digitalRead(right_paddle)==LOW)
      {
        eventState='0';
        debounce_on=false;
        debounce_off=false;
      }
    break;

  case '3': //wait for proper time to stop applying downshift CO2
    if ( millis() >= (triggerTime + downshiftDuration) && digitalRead(left_paddle)==LOW)
    {
      eventState='4';
      digitalWrite(relay_downshift,LOW);
      triggerTime=millis();
    }
    break;

  case '4'://waiting for dead time after end of button press
    //and wait for button to be unpressed before alowing state to be reset to 0
    if (millis() >= (triggerTime + downshiftDeadTime) && left_paddle==LOW)
    {
      debounce_on=false;
      eventState='0';
    }
    break;
  }
}

With just Serial.begin commented out, don't forget you still have these lines in:

 Serial.println(digitalRead(right_paddle));

You have the digitalRead inside a Serial.print so although it compiles, I suspect the digitalRead isn't actually happening since Serial.begin, didn't.

EDIT... Oh wait... I see you do the read again on the next line....

Yes that was part of my debugging, I wanted to track that value. I don't think any of the lines "Serial.print" do anything if Serial.begin is commented out. So I suspect it acts as if all of it is commented out. But does anyone know of a programming environment that would allow me to keep track of variables without the interference of Serial.begin?

But as I say in my edit above, you do the read again anyway.

Might be an idea to remove all the Serial.prints though?

I have another program identical in every way except no Serial.begin or Serial.print and it has the same issue of being buggy with the output. Sorry for not being clear! Does Serial.print take a lot of time? Maybe that time delay in all those places help?

That went through my mind too, the timing thing. Possible, I suppose.

The only reason I consider timing is because of the mechanical button push as a 5V signal. I did try to add debounce code. If I push the button down and keep it down it will very often produce the pin 5 stuck on error.

Think about what "Serial.begin" does.
Better still, look at the source of "Serial.begin"

I added a delay(5) where every serial.print was and the code works fine like that. Of course I got rid of the Serial.begin. Why would I need those delays? Next step is to take one by one out and figure out whether its a culmination of many or just a specific one. I should of thought of this earlier.. but don't hesitate to give a theory of why it needs to be slowed down.
Thanks

Edit: It would seem that under case '0' they are the most important. I got rid of all but those and they are of value 5. There is one under every if statement. Also seems if upshiftDuration is less than upshiftCutDuration the problem is gone... so it's a timing thing, thanks everyone for the contributions!