More than less than confusion

When I include an "if" statement with a "more than" or "less than" comparison, the output is opposite of what I intended. For example:

if (number > 20){
digitalWrite(ledRed, HIGH);
}
else{
digitalWrite(ledRed, LOW);
}
}

In this example I want the led to come on when the number is > 20, but it comes on in reverse. If I flip the sign it does what I want, but I would rather the code be correct than have a work around for the result I want. Any suggestions?

How have you wired your LED?

I'm using the lilypad protosnap. There led is on pin #9. The red comes on all the way up to 20 and at 20 goes off. If I change the ">" to "<" it gives the the desired output.

Here's the full code:

int ledRed = 9;

void setup()
{
Serial.begin(9600); // send and receive at 9600 baud
pinMode(ledRed, OUTPUT);
}

int number = 0;

void loop()
{
Serial.print("The number is ");
Serial.println(number); // print the number

delay(1000); // delay half second between numbers
number++; // to the next number

if (number > 20){
digitalWrite(ledRed, HIGH);
}
else{
digitalWrite(ledRed, LOW);
}
}

Thanks for the help.

I think it would make more sense to increment number before you print its value out. Also, the LED will be on forever once it increments past 20.

You need to build a simple script that does nothing more than set the LED pin HIGH. Does the LED come on, then, or go off? It sounds like you have the LED wired wrong.

I think the LED is probably wired in a desirable way but that it goes on when the input is low and off when high.

Just ran the simple code to turn it on and off, and LOW is on while HIGH is off. I guess it is reversed on the protosnap board. Thanks for the help.