Go Down

Topic: Brightness control (Read 620 times) previous topic - next topic

uird

Hey,
I'm trying to set different brightness levels, for example 25-50-75-100 levels of intensity, the led should shine in consequence. But the only examples that I find is just with "faders" that automatically switch on/off the led.
Something like,

if(readString == "25") {
      Serial.print("Intensity 25%\r\n");
...

I appreciate your help, thank you.

muddy

I'm not quite sure what you mean exactly, but if you mean just to set brightness levels of 0, 25, 50, 75 and 100%, then you should use the PWM pins and the analogWrite() function.
Keep in mind that analogWrite(pinnumber,value); accepts values between 0 and 255: 0 = 0% intensity, 255 = 100% intensity.

So, your values 0, 25, 50, 75 and 100 are translated to 0, 64, 128, 196, 255

uird

Okay, so it'll be something like,

Code: [Select]
if(readString == "25") {
      Serial.print("Intensity 25%\r\n");
      analogWrite(11,64)
}


Do you think it's okay? Thank you very much!

fungus


Okay, so it'll be something like,

Code: [Select]
if(readString == "25") {
      Serial.print("Intensity 25%\r\n");
      analogWrite(11,64)
}


Do you think it's okay? Thank you very much!


Yes.
No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

rickso234

Keep in mind that brightness levels of 0, 25, 50, 75 and 100% will look to the eye like brightness levels of about 0, 60, 80, 95 and 100%. This is due to the eye's nonlinear response to light. If you want visual levels of 0, 25, 50, 75 and 100% then you may want to start with 0, 3, 20, 50, and 100% and tweak from there. I recall seeing some algorithms that will calculate the relative "eye" brightness from LED % brightness. 

Go Up