LED is at full brightness at analogWrite(led,123)

This is the code I’m using,
#include <IRremote.h>
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
pinMode(13, OUTPUT);
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
int i=0;
void loop() {
if (irrecv.decode(&results)) {
int result = int(results.value);
if (result == -22441 || result==-1){
i+=5;
}
else
{
if (result == -8161){
digitalWrite(13, LOW);
i=0;
}
}
irrecv.resume(); // Receive the next value
Serial.println(i);
analogWrite(13,i);
}
}

For some reason, when i gets to about 123 the led is already at it’s full brightness and, the funny thing is, at 122 the led is off. Why is this happening?

analogWrite(13,i);

I'm interested in that line, which is why I referred you to the reference page.

AWOL:

analogWrite(13,i);

I'm interested in that line, which is why I referred you to the reference page.

Specifically the first sentence of the second paragraph.

I feel like this is some kind of trivia game, and I'm very tempted to blurt out the answer.

I feel like this is some kind of trivia game,

I agree, but debugging is often all about oblique glimpses of the actual answer.
It's an important skill to gain.

Has he gone to hide his head in shame?

It's the "about" that gives me second thoughts.

"I'm interested in that line, which is why I referred you to the reference page."

Yup, figured that out after reading the first sentence of that page you directed me to right after you posted your first post --just didn't reply right away.

Well damn, I could have blurted out the answer all along.

42!

AWOL:
42!

Yes, but what is the question?

They are mutually exclusive, if you know the answer, you can't know the question.

thank you Werner Heisenberg.

Yeah but you can half-fast know both...

nate890:
For some reason, when i gets to about 123 the led is already at it's full brightness ...

It's sad in a way, that you didn't say "when it gets to about 42". Then the rest of the thread would have made more sense. :wink:

More likely though, is "when it gets to 128"

This wouldn't be the LED in this thread would it?

Arduino Forum ("I have an led on my shield")

Nick, I was successful in fixing the issue -the led wasn't connected to a pwm pin

You could have gone with soft-PWM. That's where your code turns the led on and off a few 100 to 1000 times a second. Honest, it works!

"soft-PWM" soft pwm? fill me in here