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!