Struct typdef

Hi. I am making a lighting controller for a fish tank and have used some code from another design. It includes a struct to define the different channels of colour similar to below.

targetcolor.ch1
targetcolor.ch2
targetcolor.ch3
targetcolor.ch4

I also have the same but 'currentcolor.ch1' etc

If I wanted the following...
Currentcolor.ch1=targetcolor.ch1
Currentcolor.ch2=targetcolor.ch2... etc.

Could I do it a quicker way bypassing each ch part?

Is there

The power of a struct is that it can group together members of different types. Looks like you could get by with an array.

But the power of a struct (or actually a class :smiley: ) is you can do all sorts of operator overloading.

But I have to say, if you have items with stupid names link ch1, ch2 ch3... you're better of with an array I think :slight_smile:

Ill have to read up on arrays. With ch1 standing for channel 1 and so on, I am struggling to think of a less stupid name. Channelsudokufannypack1?

Numbering variables is the part that's stupid :wink:

Just make an array like

channelColors[4];
//and now you can call them like
channelColors[0]; //etc

Or if each object is to hold the RGB (max 8-bit) values of a color you can abuse a part of the FastLed library (although not using the controlling of neopixels).

CRGB ledColors;

//which you can read/write as
ledColors.red = 40;

//or as array
ledColors[1] = 50; //sets green to 50

//and you can even copy
CRGB newColors;
ledColors = newColors;