how to describe a 360º change in HUE using RGB

Hi there!

I would like to control an RGB light fixture through DMX with the DMX shield of conceptinetics and its library.

For this I need to describe the behaviour of three DMX channels: 1 (red), 2 (green), 3 (blue)

In order to create a 360º change in HUE, I need to start with one colour, lets say RED, and gradually add BLUE until its maximum value, then gradually substract RED until is gone. Then gradually add GREEN until its maximum value, and afterwards substract BLUE until its gone. Then add RED until its maximum value, and lastly substract GREEN until its gone. At the end you are again at the beginning of the cycle: RED

Capture.JPG

In this library the orders are as follow:

void loop() {
  dmx_master.setChannelValue (Channel, Value);  
  
}

I need to use channel 1, 2 and 3, with values from 0 to 255.

Can anybody guide me on how to achieve this?

Thanks!

Capture.JPG

Use the HSV or HSL color scale instead. You may need to calibrate your RGB setup to get it to work properly.

Conversion routines are available, see this for an example overview: https://en.wikipedia.org/wiki/HSL_and_HSV

There is no HSV or HSL in DMX without a converter or such. At least not with the conceptinetics library right? or am I missing something?

I would anyway like to do this by controlling the RGB channels. It cannot be so complicated, the only thing is that I have never done such coding...

Have a look at this page. Specifically the section titled “HUE”. Looking at the RGB column, you’ll notice a distinct pattern that may help you accomplish your goal.

One way may be like

//start with red
dmx_master.setChannelValue (firstChannel, 255);  
dmx_master.setChannelValue (secondChannel, 0); 
dmx_master.setChannelValue (thirdChannel, 0);  
for(int i = 0; i < 255; i++){
    dmx_master.setChannelValue (secondChannel, i);  
    delay(10); //use millis timer to avoid blocking
}
//should be at yellow (255,255,0)
for(int i = 255; i > 0; i--){
    dmx_master.setChannelValue (firstChannel, i);  
    delay(10); //use millis timer to avoid blocking
}
//should be at Green now (0,255,0)
for(int i = 0; i < 255; i++){
    dmx_master.setChannelValue (thirdChannel, i);  
    delay(10); //use millis timer to avoid blocking
}
//should be at cyan (0,255,255)

//etcetera, etcetera, etcetera
//you get the point

No idea what the rest of your code is like. So, there are probably better ways to accomplish your goal without the use of delay(), which blocks. The for loops also block. If all your code does is change the colors of the LEDs, then this would work fine.

There is no HSV or HSL in DMX without a converter or such. At least not with the conceptinetics library right? or am I missing something?

The "converter" is a C/C++ function that maps HSV values to RGB values. Such functions are available at no cost on line, if you will take a few moments to read the link, educate yourself and do a bit of searching.

May require calibration to your RGB setup.

DangerToMyself:

Thank you very much for this info! I will check it in detail.

jremington:

Thank you so much for complementing the information you provided before. Just a little bit aggresive, but we are used to this kind of attitude in the forum towards the people that, like me, have very little idea what are they searching for. For educating myself is that I am here in the forum, and for searching I need to know what am I searching for. there is no mention in wikipedia about a C/C++ function that does this conversion, so perhaps you could have pointed it out in your first post, instead of providing as little information as possible. I know that you may think you are encouraging people this way, but nope, it is not neccesarily working out...

"Doing a bit of searching", to paraphrase you, I find a lot of complicated coding that would probably take me a bit more than a while to understand, and some more to be able to apply, so I am first going to go forward with the attempt described by "DangerToMyself", which provided a lot of information which will enable to go forward a bit.

but nope, it is not neccesarily working out

With your attitude, evidently not.

Here are several options for the few lines of code that do the hsv to rgb conversion. Deep understanding of the algorithms is not required to simply use the code.

DangerToMyself:

It works lovely. Thanks! I will remember this. The resulting code follows:

#include <Conceptinetics.h>

#define DMX_MASTER_CHANNELS   3

#define RXEN_PIN              2

DMX_Master  dmx_master  (DMX_MASTER_CHANNELS, RXEN_PIN);

int Speed = 10; 


void setup() {
  dmx_master.enable ();
  dmx_master.setChannelRange (1, 512, 255);
}


void loop() {
  //RED (255,0,0)
  dmx_master.setChannelValue (1, 255);
  dmx_master.setChannelValue (2, 0);
  dmx_master.setChannelValue (3, 0);
  
  for (int i = 0; i < 255; i++) {
    dmx_master.setChannelValue (2, i);
    delay(Speed); 
  }
  //YELLOW (255,255,0)
  for (int i = 255; i > 0; i--) {
    dmx_master.setChannelValue (1, i);
    delay(Speed); 
  }
  //GREEN (0,255,0)
  for (int i = 0; i < 255; i++) {
    dmx_master.setChannelValue (3, i);
    delay(Speed); 
  }
  //CYAN (0,255,255)
  for (int i = 255; i > 0; i--) {
    dmx_master.setChannelValue (2, i);
    delay(Speed);   
  }    
  //BLUE (0,0,255)
  for (int i = 0; i < 255; i++) {
    dmx_master.setChannelValue (1, i);
    delay(Speed); 
  }  
  //MAGENTA (255,0,255)
  for (int i = 255; i > 0; i--) {
    dmx_master.setChannelValue (3, i);
    delay(Speed);   
  }    
}

Now, I would like to do the same thing with 2 light spots, but the second light spots starts the cycle a bit ahead, like for example in Yellow (255,255,0). I tried a couple of things but I cannot make it run correctly. I cannot make sense of what I am doing.

Any ideas?

camilozk: Now, I would like to do the same thing with 2 light spots, but the second light spots starts the cycle a bit ahead, like for example in Yellow (255,255,0). I tried a couple of things but I cannot make it run correctly. I cannot make sense of what I am doing.

Any ideas?

Remember me saying "If all your code does is change the colors of the LEDs, then this would work fine."?

The "for loops" and the "delays" are going to cause you all sorts of problems in trying to add more features. You probably need to go with your original DMX plan and follow the advice of jremington.

DangerToMyself: Remember me saying "If all your code does is change the colors of the LEDs, then this would work fine."?

The "for loops" and the "delays" are going to cause you all sorts of problems in trying to add more features. You probably need to go with your original DMX plan and follow the advice of jremington.

Ok, I will be thinking on this. I am a very basic arduino user, so I dont know my alternatives, that is why I am posting in this forum; to get some advice and realize in which direction to go. Right now, I am a bit lost...

-I would love to understand why the "for loops" and the "delays" will become problematic, and I certanly do not know what if the alternative for this.

-As for following the advice of jremington, the few pieces of code I see in this link, are way beyond my understanding. Not only I dont understand them, most importantly, I have no idea where to start in order to apply them for what I would like to do. I find it a little bit annoying that some people in this forum assume that if you post here, you should be able to understand things like this, and if you dont, either you are a bit stupid or not trying enough... I am a creator and I have ideas in my head that I would like to bring to reality, and sometimes I try to use tools that I do not fully understand. A lot of times, I am able to create things with tools I did not understand at first and this allows me to learn a lot and apply in the future. This is why I am here.

thanks for sharing your ideas

I did a short visualization of what I would like to do: 16 Light Spots

I am trying to do it with arduino and the DMX shield because I would like it to be a plug and play system, so that I can turn it on and it runs automatically.

https://www.youtube.com/watch?v=Qe_dvAbL-fM

camilozk:
I would love to understand why the “for loops” and the “delays” will become problematic, and I certanly do not know what if the alternative for this.

Because NOTHING else can happen during a delay(). And NOTHING else can happen during a for loop unless it is a part of that for loop. With the code I showed you, there is the double whammy of for loops that contain delays.

camilozk:
As for following the advice of jremington, the few pieces of code I see in this link, are way beyond my understanding. Not only I dont understand them, most importantly, I have no idea where to start in order to apply them for what I would like to do. I find it a little bit annoying that some people in this forum assume that if you post here, you should be able to understand things like this, and if you dont, either you are a bit stupid or not trying enough… I am a creator and I have ideas in my head that I would like to bring to reality, and sometimes I try to use tools that I do not fully understand. A lot of times, I am able to create things with tools I did not understand at first and this allows me to learn a lot and apply in the future. This is why I am here.

Ever heard the saying “You have to crawl before you can walk”? Well, you are trying to run a marathon at 2 days old with a project like the one you are trying to accomplish. I’m still crawling in the world of Arduino. And will be for a long time. Folks like jremington have put years into studying the language involved with Arduino. So, I can see why they get a bit cranky when someone new to it won’t follow their advice. Or, after being pointed in the right direction, won’t spend some of their own time to research and learn what they need to know for their project.

Like I said, I’m still crawling. I get to dabble with my project mainly on weekends for a few hours. And I have been over 6 months researching components, writing code, testing, rewriting code, testing, rewriting code, etc. Point is, your project isn’t going to be what you want it to be in a matter of a few days. It takes time and a whole lot of effort on your part.

DangerToMyself: Because NOTHING else can happen during a delay(). And NOTHING else can happen during a for loop unless it is a part of that for loop. With the code I showed you, there is the double whammy of for loops that contain delays.

Got it

you are trying to run a marathon at 2 days old with a project like the one you are trying to accomplish

I really had no idea this could be so complex. I thought exactly that I could have this running in a couple of days, and that it wouldnt involve very complex coding. And this is exactly the reason why the cranky reaction of such folks doesnt bring anything. Imagine your 6 years old kid come to you and tell you "I want to build a plane", and you give him a book about the laws of aerodinamics. How is he going to apply this knowledge? I think in this case it would be nice to let him know that what he wants to achieve is not going to be easy, and then you can help him building a paper plane. Anyway, I am bored of this discussion now... I see the behaviour of these kind of people over and over again in the forum and it is not nice. full stop

Coming back to my project, I am starting to believe that perhaps it is the simplest way to achieve my goals by simple writing the instructions. Really writing them, one line after the other, with the help of some macros in Notepad++. It will probably be a bit boring but I dont think it can take me more than two hours. And true, I am not going to be learning a lot about coding, but right now I would really like to have this specific project running, and for the future I know what am I facing when trying to drive Light Fixtures via DMX with Arduino

the few pieces of code I see in this link, are way beyond my understanding.

I believe, even if you don’t, that your understanding could be improved by some reading and study of the basic concepts, and I took the time to point you toward an overview.

Everyone doing what you want to do uses the HSV or HSL color space. HSV is close to the way we naturally perceive and understand color, and much easier to use than RGB color mixing.

The routines I linked are actually quite simple, even for a novice. Three numbers in (Hue, Saturation and Value or Luminosity) and three numbers out (R, G, B).

This is a routine I have used (the structs can be replaced by 3D vectors or arrays):

typedef struct {
    double r;       // ∈ [0, 1]
    double g;       // ∈ [0, 1]
    double b;       // ∈ [0, 1]
} rgb;

typedef struct {
    double h;       // ∈ [0, 360]
    double s;       // ∈ [0, 1]
    double v;       // ∈ [0, 1]
} hsv;

rgb hsv2rgb(hsv HSV)
{
    rgb RGB;
    double H = HSV.h, S = HSV.s, V = HSV.v,
            P, Q, T,
            fract;

    (H == 360.)?(H = 0.):(H /= 60.);
    fract = H - floor(H);

    P = V*(1. - S);
    Q = V*(1. - S*fract);
    T = V*(1. - S*(1. - fract));

    if      (0. <= H && H < 1.)
        RGB = (rgb){.r = V, .g = T, .b = P};
    else if (1. <= H && H < 2.)
        RGB = (rgb){.r = Q, .g = V, .b = P};
    else if (2. <= H && H < 3.)
        RGB = (rgb){.r = P, .g = V, .b = T};
    else if (3. <= H && H < 4.)
        RGB = (rgb){.r = P, .g = Q, .b = V};
    else if (4. <= H && H < 5.)
        RGB = (rgb){.r = T, .g = P, .b = V};
    else if (5. <= H && H < 6.)
        RGB = (rgb){.r = V, .g = P, .b = Q};
    else
        RGB = (rgb){.r = 0., .g = 0., .b = 0.};

    return RGB;
}

If you want people to write code for you, post on the Gigs and Collaborations forum section. You may be asked to pay for the help.

jremington:
I believe, even if you don’t, that your understanding could be improved by some reading and study of the basic concepts, and I took the time to point you toward an overview.

Everyone doing what you want to do uses the HSV or HSL color space. HSV is close to the way we naturally perceive and understand color, and much easier to use than RGB color mixing.

The routines I linked are actually quite simple, even for a novice. Three numbers in (Hue, Saturation and Value or Luminosity) and three numbers out (R, G, B).

This is a routine I have used (the structs can be replaced by 3D vectors or arrays):

typedef struct {

double r;      // ∈ [0, 1]
    double g;      // ∈ [0, 1]
    double b;      // ∈ [0, 1]
} rgb;

typedef struct {
    double h;      // ∈ [0, 360]
    double s;      // ∈ [0, 1]
    double v;      // ∈ [0, 1]
} hsv;

rgb hsv2rgb(hsv HSV)
{
    rgb RGB;
    double H = HSV.h, S = HSV.s, V = HSV.v,
            P, Q, T,
            fract;

(H == 360.)?(H = 0.):(H /= 60.);
    fract = H - floor(H);

P = V*(1. - S);
    Q = V*(1. - Sfract);
    T = V
(1. - S*(1. - fract));

if      (0. <= H && H < 1.)
        RGB = (rgb){.r = V, .g = T, .b = P};
    else if (1. <= H && H < 2.)
        RGB = (rgb){.r = Q, .g = V, .b = P};
    else if (2. <= H && H < 3.)
        RGB = (rgb){.r = P, .g = V, .b = T};
    else if (3. <= H && H < 4.)
        RGB = (rgb){.r = P, .g = Q, .b = V};
    else if (4. <= H && H < 5.)
        RGB = (rgb){.r = T, .g = P, .b = V};
    else if (5. <= H && H < 6.)
        RGB = (rgb){.r = V, .g = P, .b = Q};
    else
        RGB = (rgb){.r = 0., .g = 0., .b = 0.};

return RGB;
}

Thank you very much. I will try to apply this to my project, even though I dont think I have enough knowledge to do so. I dont really know what a 3D vector or array is, etc, etc… so it wont be easy for me to apply this. That is why I came to the forum, for some guidance.

If you want people to write code for you, post on the Gigs and Collaborations forum section. You may be asked to pay for the help.

I dont really understand from where you deduce that I am expecting somebody to write code for me. I never said so, neither I expect it to happen, but if it makes you happy to continue implying this, be happy.

Many people take advantage of the "Gigs and Collaborations" forum section, and my reference to it was informational only.

You are extremely quick to take offense. If you find this hobby too difficult, choose another one.

Regarding knowledge about RGB and HSV relationships, read up on ‘colour space’. In your application, that’s probably all you need, but if you’re looking to video or other applications, it gets more complex when managing ‘gamut’, as the various technologies handle saturation quite differently.

lastchancename: Regarding knowledge about RGB and HSV relationships, read up on ‘colour space’. In your application, that’s probably all you need, but if you’re looking to video or other applications, it gets more complex when managing ‘gamut’, as the various technologies handle saturation quite differently.

Thank you very much!