Pages: [1]   Go Down
Author Topic: Brightness control  (Read 436 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Eindhoven Netherlands
Offline Offline
Jr. Member
**
Karma: 2
Posts: 57
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay, so it'll be something like,

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

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

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 118
Posts: 4538
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay, so it'll be something like,

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

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

Yes.
Logged

No, I don't answer questions sent in private messages...

Manchester, NH
Offline Offline
Full Member
***
Karma: 0
Posts: 116
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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. 
Logged

Pages: [1]   Go Up
Jump to: