Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello.I have a led strip and I want to fade in and fade out the strip with yellow color (RGB = (255,255,0) ).
I use 1 for-loop to fade in and 1 for-loop to fade out,but the color changes,but I want to change only brightness,not color.
I asked in arduino forum, and told me that I need a function to convert Hue, Saturation, Value (HSV) into RGB.I searched a lot of time,but I didn't find anything,just some complicated functions.
Can anyone suggest me some link using HSV->RGB ,or does anyone know how to solve my problem?
(I want to fade in and fade out yellow color from 0->255 and 255->0 ,but intermediate color changes.)
Before ask in arduino forum,I made this without success as I said:

What I have tried:

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


int *BrightnessValue = NULL;

void setup() 
{
  pinMode(REDcolor, OUTPUT);
  pinMode(GREENcolor, OUTPUT);
  pinMode(BLUEcolor, OUTPUT);
}
 
 
void loop()
{
  for(*BrightnessValue = 0; *BrightnessValue < 255; (*BrightnessValue)++ )
  {
    yellow_color();
    delay(15);
  }
  for(*BrightnessValue = 255; *BrightnessValue > 0; (*BrightnessValue)-- )
  {
    yellow_color();
    delay(15);
  }
}


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(200 , 20 , 0);
}
void fuchsia_color()
{
  getColor(*BrightnessValue , 0 , *BrightnessValue);
}





Thanks a lot.
Any help would be appreciated.
Posted
Updated 18-Dec-20 22:53pm

1 solution

HSV->RGB - Google Search[^]. You can also use the different RGB values for different shades of any colour. See RGB Color Codes Chart 🎨[^].
 
Share this answer
 
v2
Comments
Nick_is_asking 19-Dec-20 5:50am    
Finally I will write the algorithm I found (Hsv to Rgb),because I didn't find any functions.Anyway thank you!!!
Richard MacCutchan 19-Dec-20 6:00am    
There is a solution in one of the links on the first Google page.
Nick_is_asking 19-Dec-20 6:06am    
Thank you.I 'm thinking to write it on my own to practice more.If I have any problem, I will ask here.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900