Easy code; not working.

Hello. I just got my own arduino duemillanove. I wrote some simple code, but its not working, the only option that won't work is the V option.

int ledPin = 9;
int incomingByte;

void setup() {
  pinMode(ledPin, OUTPUT);  

void loop() {
  incomingByte = Serial.read();
  if(incomingByte == 'T' || incomingByte == 't') {
    digitalWrite(ledPin, HIGH);
    Serial.println("Turned LED on!");
  else if(incomingByte == 'F' || incomingByte == 'f') {
    digitalWrite(ledPin, LOW);
    Serial.println("Turned LED off!");
  else if(incomingByte == 'V' || incomingByte == 'v') {
     Serial.println("Please enter fade value: ");
     if(Serial.available() > 0) {
       incomingByte = Serial.read();
     int fade = incomingByte;
     analogWrite(ledPin, fade); 

It seems to have a value of 118 or -1, by default, and I don't really understand why. Help please?

-1 means you forgot to check Serial.available before reading

118 is lower-case 'v'. You're not checking "Serial.avaliable ()" before reading your command character, so as has been pointed out, "Serial.read" will return -1.

Your fade value is going to be difficult to enter, because you'll have to find the exact character code you want, and lower levels will be non-printing character codes.

The "else"s are mostly redundant, you may as well just use fall-through - it will save on indentation.

"incomingByte" doesn't need global scope.

If you keep your code as is (no check for serial available, no fall through) you can just modify your code to wait for the fade value as follows:

     Serial.println("Please enter fade value: ");
     while (Serial.available() <= 0)  ; // wait for next character
     incomingByte = Serial.read();

If you’re on Windows you can enter a three digit (0-255 range) fade value using the numeric keypad (press and hold Alt, enter three digits, release alt and press enter).