Why the max value of analog output is 255?

The project is to light on LED with sine function, the code is as bellow:

/* Project 07 blink with sin */

int ledPin = 11;
float sinVal;
int ledVal;

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

void loop()
{
for (int x = 0; x < 180; x++)
{
sinVal = (sin(x*(4.14/180)));
ledVal = int(sinVal*255); // Why it is 255?
analogWrite(ledPin, ledVal);
delay (25);
}
}

Light LED with Pin11, and the max value of analogwrite is 255, why is it 255?

analogWrite() - Arduino Reference. Edit, link corrected.

The function only expects values between 0 and 255.

Weedpharma

weedpharma:
http://https://www.arduino.cc/en/Reference/analogWrite

The function only expects values between 0 and 255.

Weedpharma

Buddy, I can't click in the link, maybe the reason is my location, China. Sorry, I see the detail information about function analogWrite, thanks a lot.

It is an 8-bit binary number - the values possible for an 8-bit binary number is the range 0 to 255.

If you need more, use TLC5940 it have 12 bit control (0 - 4095).

If you're willing to poke at registers instead of using analogWrite(), you can make the '328p output 16-bit PWM (0 ~ 65535 ) instead of 8-bit (0~255) on two channels - timer1 is 16-bit - if you need more precise control over the duty cycle