Problem with simple switch

Hi,

I'm having a hard time getting this simple switch to turn on an LED (don't judge me!!). Here's the code I'm running (from the Arduino website, only the pin values have been altered. I also added a println for reading):

int inPin = 10;         // the number of the input pin
int outPin = 4;       // the number of the output pin

int state = HIGH;      // the current state of the output pin
int reading;           // the current reading from the input pin
int previous = LOW;    // the previous reading from the input pin

// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0;         // the last time the output pin was toggled
long debounce = 200;   // the debounce time, increase if the output flickers

void setup()
{
  Serial.begin(9600);
  pinMode(inPin, INPUT);
  pinMode(outPin, OUTPUT);
}

void loop()
{
  reading = digitalRead(inPin);
  Serial.println(reading);

  // if the input just went from LOW and HIGH and we've waited long enough
  // to ignore any noise on the circuit, toggle the output pin and remember
  // the time
  if (reading == HIGH && previous == LOW && millis() - time > debounce) {
    if (state == HIGH)
      state = LOW;
    else
      state = HIGH;

    time = millis();    
  }

  digitalWrite(outPin, state);

  previous = reading;
}

And here is the super weird output:
.
.
.
0
0
0
0
0
0
0+êRj¤j¤j¤j¤j¤j¤j¤j¤j¤...

What in the world does this mean?

Perhaps the program crashed out - is the code you posted all there is? It seems innocuous.

Yes, it's all there. From what I can tell the program didn't crash, the two repeating symbols continued running to infinity.

I've seen characters like that when the baud setting in my serial monitor was different than in my sketch.

Do you have a current limiting resistor on the LED?
Do you have a pull-up or pull-down resistor on the switch? If you don't, you can use the builtin pullup resistor.

I doubt you are running into this already, but "time" should be an unsigned long.

Try printing an introductory message to serial in setup so you can verify that your baud rate matches.

Bauds match, both running at 9600. I verified with a "hello world" in setup().

I'm not using a resistor for the LED as of now, but its a good led and it's working fine (I tested it).

Fixed time to be an unsigned long. Still no change.

Any guess as to what could be going on?

I'm not using a resistor for the LED as of now, but its a good led

sp. "was a good LED"

Since, you write data every time through loop(), at 9600 baud I think you are stuffing bytes into the serial buffer faster than they can be transmitted.

Serial.print used to pause until the data was transmitted, but the new asynchronous implementation does not.
I don't know how the newer asynchronous implementation handles overflow, but it might be you get the garbage when the buffer is too full.

Try increasing the baud rate and/or adding a little delay in the loop.

EDIT: it may be that adding a Serial.flush() would work too: Serial.flush() - Arduino Reference

I think you are stuffing bytes into the serial buffer faster than they can be transmitted.

I don't.

but it might be you get the garbage when the buffer is too full.

Please.

Ummmm.... see reply #4?? http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1295434903/all

Doesn't the current implementation of Serial.print return without waiting for the data to be transmitted?

Umm...and?

Edit: you mean I misspelt "serial"? Sorry.

Your coyness, sir, is very fetching, but perhaps not entirely helpful in enlightening me on the source of my errors

Are you saying that in the posted code, execution time of loop() will never be so fast that characters will be deposited in the serial buffer at a rate greater they would be transmitted at 9600 baud?

If the buffer is full, the write method waits until it is not. The people who redesigned the library aren't that stupid.

I stand with my suggestion to put a resistor on the LED. The overcurrent could be causing any range of problems.

Your coyness, sir, is very fetching,

By some curious oversight of the honours system, Her Majesty has not deemed it necessary to bestow a knighthood on me.
The honorific is completely, though inexplicably, superfluous.