Led strip 5V

Hello.I have a 0.5m led strip (5V) and an arduino UNO.I 'm a beginner with led strips and I want for example to
show yellow color which is RGB = (255, 255, 127) ,but I receive blue color as output.
My led strip

#define REDPIN 5
#define GREENPIN 3
#define BLUEPIN 6
  
void setup() {
  pinMode(REDPIN, OUTPUT);
  pinMode(GREENPIN, OUTPUT);
  pinMode(BLUEPIN, OUTPUT);
}
 
 
void loop() {

  analogWrite(REDPIN , 255);  
  analogWrite(GREENPIN , 255);  
  analogWrite(BLUEPIN , 127);
}

I checked wiring , code and I think is good. ( red to pin 5 , green to pin 3 and blue to pin 6 , 5V to pin 5V)
Any ideas?
Thanks. :slight_smile:

Arduino Uno
Ubuntu 18

Some devices work with negative logic, where LOW means "ON" and HIGH means "OFF.

Does this code produce red light?

  analogWrite(REDPIN , 127); 
  analogWrite(GREENPIN , 255); 
  analogWrite(BLUEPIN , 255);

I have noticed that when I write this:

  analogWrite(REDPIN , 255);  
  analogWrite(GREENPIN , 255);  
  analogWrite(BLUEPIN , 0);

blue is ON
when I write this:

  analogWrite(REDPIN , 0);  
  analogWrite(GREENPIN , 255);  
  analogWrite(BLUEPIN , 255);

red is ON
etc.....

Yes (127,255,255) is red .Also, I'm thinking a code trick to reverse all.Any ideas?

Sure: don't send the value to the strip, but 255 minus the value. :wink:

Yesss.That's works. Thank you very much!!!

Hello.I want to control the brightness of led strip any time I want,but I have a problem with yellow_color() function.
If the parameter of brightness function is (for example) 45 it works good(it shows yellow color) ,but If I set brightness to 235(for example) ,then it shows green color.
Generally ,if I want to have other colors such as RGB = (124 , 249 , 43) I will have problems ,because if I wanted to reduce brightness ,color would change.But, I don't want to change just the color, but the brightness of it .I couldn't think anything else to control the brightness.
How analogWrite() will check RGB values and control brightness at the same time?

#define REDcolor 5
#define GREENcolor 3
#define BLUEcolor 6

int del = 1000;
int fadeSpeed = 10;
int *BrightnessValue = NULL;

void setup() 
{
  pinMode(REDcolor, OUTPUT);
  pinMode(GREENcolor, OUTPUT);
  pinMode(BLUEcolor, OUTPUT);
}
 
 
void loop()
{
  /*blue_color();
  delay(del);
  green_color();
  delay(del);
  red_color();
  delay(del);
  white_color();
  delay(del);
  cyan_color();
  delay(del);
  yellow_color();
  delay(del);
  fuchsia_color();
  delay(del);*/
  brightness(55);
  blue_color(); 
}

/*void fade_in(char *color)
{
  if(strcmp(color , REDcolor) == 0)
  {
    analogWrite(GREENcolor , 255 - 0); // reverse logic
    analogWrite(BLUEcolor , 255 - 0); // reverse logic
    for(int 
  }
}*/

void brightness(int b_value)
{
  BrightnessValue = &b_value;
}

void getColor(int red_value , int green_value , int blue_value) // reverse logic 
{
  analogWrite(REDcolor, 255 - red_value);
  analogWrite(GREENcolor , 255 - green_value);
  analogWrite(BLUEcolor , 255 - blue_value);
  
}


void blue_color()
{
  getColor(0 , 0 , *BrightnessValue);
}
void red_color()
{
  getColor(*BrightnessValue , 0 , 0);
}
void green_color()
{
  getColor(0 , *BrightnessValue , 0);
}
void white_color()
{
  getColor(*BrightnessValue , *BrightnessValue , *BrightnessValue);
}
void cyan_color()
{
  getColor(0 , *BrightnessValue , *BrightnessValue);
}
void yellow_color()
{
  getColor(*BrightnessValue , 45 , 0);
}
void fuchsia_color()
{
  getColor(*BrightnessValue , 0 , *BrightnessValue);
}

Any ideas?
I'm very stuck...
Thanks.

getColor(*BrightnessValue , 45 , 0);

The colour of your strip is determined by the ratio of red to green to blue. In other words, the relative amounts of red, green and blue. Because that 45 is fixed, when the brightness value changes, the ratio changes and so the colour changes.

I think what you need here is a function to convert Hue, Saturation, Value (HSV) into RGB. That function will calculate the red, green and blue values correctly for any brightness.

int *BrightnessValue = NULL;

As a beginner at coding, you should not be using pointers, it's like running with scissors. In this sketch, there is no need to use pointers at all. It makes the sketch more complex for no benefit.

Hhmmm.Thanks for the update. Also, I searched some links about HSV->RGB for fade in/out leds ,but I found it difficult to understand.Can you suggest me a link that use HSV->RGB method for fade in and fade out for only one color (just to understand the method and continue).The links I found doesn't help me to understand. I have been using C language for 1 year (and this is not enough).

Thanks in advance. :slight_smile:

Any help would be appreciated.

I am looking for you. I don't really like what I found so far...

I'm searching for more than 1 hour and I found nothing. Interesting...

OK Brightness.

What color is 255,0,0?

What color is 100,0,0?

What color is 50,0,0?

What actually did change?

Now take the color 255,102,204. Notice there is a ratio to RGB. By keeping the ratio but lowering the number, what happens to the LED?

Here is an example/snippet of use

leds.setPixelColor(position, leds.Color( value, 0, value * .91) ); // pink

Where value is a desired intensity and the other values are a percentage of value to create, in the above case, pink light of varying intensity.

leds.setPixelColor(position, leds.Color( 0, 0, value) ); // blue
leds.setPixelColor(position, leds.Color( value, value, 0)); // yellow
leds.setPixelColor( position, leds.Color( value, value * .3, 0) ); // orange

Hope you get the gist.

Hi.As I said I want to fade in and fade out (with 2 for loops as I did) the led strip with yellow color (0->255 and 255->0) ,but when the brightness changes ,the color changes and this is a problem (from yellow goes to green).
But finally I will write the algorithm I found to convert HSV to RGB on my own,because I didn’t find any functions to do this. Anyway, thank you all for your time!!! :slight_smile:

I wrote some HSV to RGB functions for you to try:

byte grnFromHSV(int hue, byte sat, byte val) {
  while (hue >= 360) hue -= 360;
  while (hue < 0) hue += 360;
  byte c = val * sat / 255;
  byte m = val - c;
  if (hue < 60) return m + c * hue / 60;
  else if (hue < 180) return m + c;
  else if (hue < 240) return m + c * (240 - hue) / 60;
  else return m;
}

byte redFromHSV(int hue, byte sat, byte val) {
  return grnFromHSV(hue + 120, sat, val);
}

byte bluFromHSV(int hue, byte sat, byte val) {
  return grnFromHSV(hue - 120, sat, val);
}