Calling a variable from one segment to another

Hello, I can't figure this out nor do I know if it's even possible.
Here is my delima....
I have a segment like below

Void ledprogram(xyz) (number of case desired, case one RGB follow, case 2 flash ect)

However I have a few cases that need more variables like color, speed.

What I'm trying to do is when input the first part ledprogram(2) it works fine. But how can I make it where if I choose 3 instead of 2 the variables for 3 need to passed. So case 3 needs additional information where case 2 doesn't
I was thinking like if led program 3 is called that selection can be 0assed to another case that has the variables already done.

I'm really stuck here I appreciate any help provided and please don't think I'm dumb :=)

i think when you wrote "segment" you mean "function"
and i'm not sure if by "case" you mean argument.

in the example below, you can define a function with default argument values. in the case below, the function can be called with 1 or 2 arguments. if you specify just one argument, the 2nd argument has a default value of zero

void
myFunc (
    int arg1,
    int arg2 = 0)
{
    printf (" %s: %d %d\n", __func__, arg1, arg2);
}

this example runs on my laptop where printf() can be used

Sorry for my bad terms. Im lost on your example. let me add some code in to make better sense.....

  void ledsprogram(0, effect, bright) {
  
    EEPROM.put(0, effect);
  FastLED.setBrightness(bright);

  switch(effect) {
    
    case 0  : {
                 RGBLoop();
                break;
              }
Now i need to pass the effect variable to

 EEPROM.get(0, effect); 
  FastLED.show          then from what every value effect is , i need to take that value and use it to do another case list (like one above) which has the variable (speed, fade, ect.) already filled out, Is this making sense?

?
are you simply saying different processing is needed for each value of "effect"

    switch(effect) {
     case 0:
         ...
         break;

     case 1:
         ...
         break;

     case 2:
         ...
         break;

     case 3:
         ...
         break;
    }

Yes. But not all of them say case 1 has no variables. Case two has 3. Case 3 has 2.

I was thinking of Making another case list
So if effect gives the value of 3

I want to return 3 on my other case list that has the variables filled out already. Or would there be a better way?

no sure what you're asking

if some "effects" don't need all the arguments, just set the unnecessary arguments to zero when the function is called.

Oh OK! I'll try that didn't know 0 was a way to null or skip that veroable

it could be any value, right, because that effect doesn't use the value

Another way is to make a 'variadic' function: one that takes a variable number of arguments.
https://en.cppreference.com/w/cpp/utility/variadic

Hello
Another way to work with different parameter per function is to work with structured data block and a reference.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.