Go Down

Topic: Led Control Help (Read 891 times) previous topic - next topic

1995zach

Hi,

I'm not sure why I am having a hard time wrapping my head around this but I'm working on a project where I have an rgb led strip and I want to control the color and brightness of the strip with my arduino. I can control the color just fine but when it comes to brightness I'm not sure where to start.

dannable

Which rgb led strip? Link?
Beginners guide to using the Seeedstudio SIM900 GPRS/GSM Shield

1995zach

http://www.ebay.com/itm/5M-5050-SMD-RGB-Waterproof-300-LED-60leds-m-Strip-Light-12V-Black-PCB-/251299906156?hash=item3a82a4426c

Its just your standard 5050 led strips.

jack wp

" I can control the color just fine but when it comes to brightness I'm not sure where to start."
If your script is working to control the color, it should be pretty easy to control the brightness of each color with analogWrite().

Show us a copy of your code please.

1995zach

int redPin = 9;
int greenPin=11;
int bluePin = 10;
int bright=.1;

void setup()
{
 pinMode(redPin, OUTPUT);
 pinMode(greenPin, OUTPUT);
 pinMode(bluePin, OUTPUT);
}

void loop()
{
 setColor(167, 0, 255);
}

void setColor(int red, int green, int blue)
{
 #ifdef COMMON_ANODE
 red = (255 - red)*bright;
 green = (255 - green)*bright;
 blue = (255 - blue)*bright;
 #endif
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
 
}

The issue I am running into is overall brightness or intensity. I'm just not sure how to program that or if I need to handle that in the circuit

jack wp

#5
Sep 18, 2015, 06:35 pm Last Edit: Sep 18, 2015, 06:37 pm by jack wp
Try this for the loop()

Code: [Select]
void loop()
{
 setColor(167, 255, 255);
 delay(1000);
 setColor(20, 200, 25);
 delay(1000);
 setColor(40, 50, 25);
 delay(1000);
 setColor(9, 20, 25);
 delay(1000);
}


BTW "int bright=.1;" will not work. int will not take decimals.


1995zach

Alright, Cool. I didn't even notice I put int instead of float but is there a way to have a variable control the brightness?

jack wp

" is there a way to have a variable control the brightness?"

There is a way to have a variable to control the three different colors brightness.

Try the code I suggested, and if it works sorta, we can discuss using a single variable.

1995zach

Alright, Thanks but I actually found a better solution to my problem. I think I'm going to us the HSV model which allows for the control I need. Once again thanks for the help, Ill keep you guys posted on what happens.

Go Up