Arduino Forum

Using Arduino => LEDs and Multiplexing => Topic started by: 1995zach on Sep 18, 2015, 04:47 pm

Title: Led Control Help
Post by: 1995zach on Sep 18, 2015, 04:47 pm
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.
Title: Re: Led Control Help
Post by: dannable on Sep 18, 2015, 04:56 pm
Which rgb led strip? Link?
Title: Re: Led Control Help
Post by: 1995zach on Sep 18, 2015, 06:03 pm
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.
Title: Re: Led Control Help
Post by: jack wp on Sep 18, 2015, 06:10 pm
" 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.
Title: Re: Led Control Help
Post by: 1995zach on Sep 18, 2015, 06:27 pm
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
Title: Re: Led Control Help
Post by: jack wp on Sep 18, 2015, 06:35 pm
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.

Title: Re: Led Control Help
Post by: 1995zach on Sep 18, 2015, 06:55 pm
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?
Title: Re: Led Control Help
Post by: jack wp on Sep 18, 2015, 07:03 pm
" 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.
Title: Re: Led Control Help
Post by: 1995zach on Sep 18, 2015, 07:26 pm
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.