Serial Output Stops

After a while of having my arduino project plugged into the PC, it eventually stops outputting to the serial port. The weird thing is that that if I send a serial command to the arduino ( so "a" in this scenario) it works fine. So is something getting filled up and not sending data to the PC or what is happening?

Here's my code:

/*
  Input Pull-up Serial

  This example demonstrates the use of pinMode(INPUT_PULLUP). It reads a digital
  input on pin 2 and prints the results to the Serial Monitor.

  The circuit:
  - momentary switch attached from pin 2 to ground
  - built-in LED on pin 13

  Unlike pinMode(INPUT), there is no pull-down resistor necessary. An internal
  20K-ohm resistor is pulled to 5V. This configuration causes the input to read
  HIGH when the switch is open, and LOW when it is closed.

  created 14 Mar 2012
  by Scott Fitzgerald

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/InputPullupSerial
*/
int led = 13;
void setup() {
  //start serial connection
  Serial.begin(9600);
  //configure pin 2 as an input and enable the internal pull-up resistor
  pinMode(10, INPUT_PULLUP);
  pinMode(12, INPUT_PULLUP);
  pinMode(13, OUTPUT);

}

void loop() {
  String input = "";
  //read the pushbutton value into a variable
  int onButton = digitalRead(12);
  int offButton = digitalRead(10);
  //print out the value of the pushbutton
  
  if (onButton == LOW){
 
    while (onButton == LOW){
    
    delay(50);
    onButton = digitalRead(12);
    }
    Serial.println("onButton");
  }
  if (offButton == LOW){
 
    while (offButton == LOW){
   
    delay(50);
    offButton = digitalRead(10);
    }
    Serial.println("offButton");
  }


if (Serial.available() > 0) {
    int inByte = Serial.read();
    // do something different depending on the character received.
    // The switch statement expects single number values for each case; in this
    // example, though, you're using single quotes to tell the controller to get
    // the ASCII value for the character. For example 'a' = 97, 'b' = 98,
    // and so forth:
 if (inByte == 'a'){
  digitalWrite(13, HIGH);
 }
    if (inByte == 'b'){
  digitalWrite(13, LOW);
 }
    }
  }

Thanks in advance for your help!

The way your program is written it looks as if the Arduino won't print unless you press a button - is that the intention?

It also seems that if (for example) onButton is LOW nothing can happen until it changes to HIGH - because of the WHILE.

It would help if you describe the behaviour that you want to achieve. I suspect your blocking code is not the way to go about it.

...R

I updated my code to be a lot cleaner. I'll post in this thread again if this doesn't fix it.

/*

*/
int led = 13;
int flag;
void setup() {
  //start serial connection
  Serial.begin(9600);
  //configure pin 2 as an input and enable the internal pull-up resistor
  pinMode(10, INPUT_PULLUP);
  pinMode(12, INPUT_PULLUP);
  pinMode(13, OUTPUT);



}

void loop() {
  //read the pushbutton value into a variable
  int onButton = digitalRead(12);
  int offButton = digitalRead(10);
  // if the button is pushed, then print out the button that was pushed. Set a flag so it only is done once
  if (onButton == HIGH && flag != 1){
    Serial.println("onButton");
    flag = 1;
  }

  if (offButton == HIGH && flag != 2){
    Serial.println("offButton");
    flag = 2;
  }
  


if (Serial.available() > 0) {
    int inByte = Serial.read();
    // do something different depending on the character received.
    // The switch statement expects single number values for each case; in this
    // example, though, you're using single quotes to tell the controller to get
    // the ASCII value for the character. For example 'a' = 97, 'b' = 98,
    // and so forth:
 if (inByte == 'a'){
  digitalWrite(13, HIGH);
 }
    if (inByte == 'b'){
  digitalWrite(13, LOW);
 }
    }
  }