Looking for advice on how to change up the following code to address a full led strip instead of a single led. I would like to use three pots to control the RGB of the line. Essentially looking to color mix with them. Thanks for the help!
Connect the LED's anode lead to +5v and connect the 3 RGB cathode leads to digital pins 9, 10, 11 respectively. Use 220 Ohm resistors on each pin of the cathode pins.
Wire up each potentiometer's first pin to +5v, the third pin to ground, and the second pin to analog pins 0, 1, 2. 0 is for Red, 1 is for Green, and 2 is for Blue.
Upload this source code to the arduino. Then turn up and down each pot to change the color of the LED.
Questions or problems: ziptiesispro@yahoo.com
// Init the Pins used for PWM
const int redPin = 9;
const int greenPin = 10;
const int bluePin = 11;
// Init the Pins used for 10K pots
const int redPotPin = 0;
const int greenPotPin = 1;
const int bluePotPin = 2;
// Init our Vars
int currentColorValueRed;
int currentColorValueGreen;
int currentColorValueBlue;
void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop()
{
// Read the voltage on each analog pin then scale down to 0-255 and inverting the value for common anode
currentColorValueRed = (255 - map( analogRead(redPotPin), 0, 1024, 0, 255 ) );
currentColorValueBlue = (255 - map( analogRead(bluePotPin), 0, 1024, 0, 255 ) );
currentColorValueGreen = (255 - map( analogRead(greenPotPin), 0, 1024, 0, 255 ) );
// Write the color to each pin using PWM and the value gathered above
analogWrite(redPin, currentColorValueRed);
analogWrite(bluePin, currentColorValueBlue);
analogWrite(greenPin, currentColorValueGreen);
}
fultonm11:
Sure. As of my understanding this code only controls a single led. I would like to control an entire strip, 2 meters, of LEDs. 60 LEDs per meter.
A link to the strip would be useful. Are the LEDs individually addressable?
Not sure if it is a digital strip where the can be addressed individually. Would I need to address them individually in the code in order to control all the red in entire strip? Same goes for green and blue...
That's normally led strip and I think your code works fine with that. I think that your code controls the full led strip, not only one led. In that led strip you can't control only one led. Please test your code with your led strip and feel free to ask help if you need.
As a side note: Is it possible to code for a button that when switched on would activate a color chase or run, then when off, default to the manual color mixing?
The LED strip linked to above requires 12V to operate. The output from analogWrite() will need to be switched by a suitable device to provide enough voltage and current and it is not obvious in the thread that this has been taken into account.
It looks to me as though you will not be able to do a colour chase with that LED strip because all the LEDs of the same colour will come on at the same time along the length of the strip.
As a side note: Is it possible to code for a button that when switched on would activate a color chase or run, then when off, default to the manual color mixing?
No it is not possible to do this with that strip. To do this you need a strip where you can individually address each LED. These are more expensive strips and involve squirting data into then through one arduino output pin. The code to do this is much more involved.
After some research I undertand why this isn't possible. Would it be possible then to doe a more linear effect? Such as a hue sat cycle where all the LEDs are the same color just moving around the color wheel?
Also, I saw this this would need 12v power with the correct amperage, the board itself couldn't output that.