Make multiple fadings in the same time

Hello there

I have multiple straps connected to my Adafruit Trinket and I would like them to fade in a certain order, with a little transition.

For example, if I have 3 straps of LEDs, I would like the first strap to light up, then at ~40% luminosity, the second strap would begin to light up too, and then the third strap, etc.

Here’s how it would look like:

Edit: It seems the picture is dead, so here’s the link: Imgur: The magic of the Internet

Phase 1, the first strap begins to light up

Phase 2, the strap is lit up and the second begins

Phase 3, the second is lit up and the third begins

Phase 4, the first begins to attenuate and the third is lit up

My problem is that, I think I sort of managed to make this effect (Can’t verify now, didn’t receive my LEDs for now ) but it’s already taking 10Kb on my card and the limit is 28Kb, and I’ll have to copy this behavior with a lot of other straps.

Is there a way to drastically reduce the number of instructions ?

I joined my code as a file because it’s too heavy for this website.

Comments etc are in french so if you have trouble with anything, feel free to ask.

Thank you for your time !

LumieresArmureZinogre.ino (10.7 KB)

You don’t call fonduEpaules(). May I assume that that is the function that chews away the memory? If so, you can make your while loops more intelligent.

E.g. the first part of founduEpaules() currently is

void fonduEpaules() {
  // 5 6 s'allument, 70 on passe à 4567
  int couleurLeds56 = 0;
  int couleurLeds47 = 0;
  int couleurLeds2389 = 0;
  int couleurLeds110 = 0;
  while (couleurLeds56 < 70) {
    couleurLeds56 += vitesse;
    definirIntensite(stripShoulders, 4, couleurLeds56);
    definirIntensite(stripShoulders, 5, couleurLeds56);
    stripShoulders.show();
    delay(50);
  }
  // à 140 ( pour 5 6 ) on passe à 23456789
  while (couleurLeds56 < 140) {
    couleurLeds56 += vitesse;
    definirIntensite(stripShoulders, 4, couleurLeds56);
    definirIntensite(stripShoulders, 5, couleurLeds56);
    couleurLeds47 += vitesse;
    definirIntensite(stripShoulders, 3, couleurLeds56);
    definirIntensite(stripShoulders, 6, couleurLeds56);
    stripShoulders.show();
    delay(50);
  }
  //à 210 (pour 5 6 ) on passe à 12345678910
  while (couleurLeds56 < 210) {
    couleurLeds56 += vitesse;
    definirIntensite(stripShoulders, 4, couleurLeds56);
    definirIntensite(stripShoulders, 5, couleurLeds56);
    couleurLeds47 += vitesse;
    definirIntensite(stripShoulders, 3, couleurLeds56);
    definirIntensite(stripShoulders, 6, couleurLeds56);
    couleurLeds2389 += vitesse;
    definirIntensite(stripShoulders, 1, couleurLeds2389);
    definirIntensite(stripShoulders, 2, couleurLeds2389);
    definirIntensite(stripShoulders, 7, couleurLeds2389);
    definirIntensite(stripShoulders, 8, couleurLeds2389);
    stripShoulders.show();
    delay(50);
  }
}

If I call (the above stripped) fonduEpaules() in loop(), the compile result for a ProMicro is

  Sketch uses 9176 bytes (32%) of program storage space. Maximum is 28672 bytes.
  Global variables use 301 bytes (11%) of dynamic memory, leaving 2259 bytes for local variables. Maximum is 2560 bytes.

Rewriting the above only using a single while-loop

void fondueEpaules()
{
  // 5 6 s'allument, 70 on passe à 4567
  int couleurLeds56 = 0;
  int couleurLeds47 = 0;
  int couleurLeds2389 = 0;
  int couleurLeds110 = 0;


  while (couleurLeds56 < 210)
  {
    if (couleurLeds56 < 70)
    {
      couleurLeds56 += vitesse;
      definirIntensite(stripShoulders, 4, couleurLeds56);
      definirIntensite(stripShoulders, 5, couleurLeds56);
      stripShoulders.show();
      delay(50);
      continue;
    }
    else if (couleurLeds56 < 70)
    {
      couleurLeds56 += vitesse;
      definirIntensite(stripShoulders, 4, couleurLeds56);
      definirIntensite(stripShoulders, 5, couleurLeds56);
      couleurLeds47 += vitesse;
      definirIntensite(stripShoulders, 3, couleurLeds56);
      definirIntensite(stripShoulders, 6, couleurLeds56);
      stripShoulders.show();
      delay(50);
      continue;
    }
    else
    {
      couleurLeds56 += vitesse;
      definirIntensite(stripShoulders, 4, couleurLeds56);
      definirIntensite(stripShoulders, 5, couleurLeds56);
      couleurLeds47 += vitesse;
      definirIntensite(stripShoulders, 3, couleurLeds56);
      definirIntensite(stripShoulders, 6, couleurLeds56);
      couleurLeds2389 += vitesse;
      definirIntensite(stripShoulders, 1, couleurLeds2389);
      definirIntensite(stripShoulders, 2, couleurLeds2389);
      definirIntensite(stripShoulders, 7, couleurLeds2389);
      definirIntensite(stripShoulders, 8, couleurLeds2389);
      stripShoulders.show();
      delay(50);
    }
  }
}

If I call (the above) fonduEpaules() in loop(), the compile result for a ProMicro is

  Sketch uses 8880 bytes (30%) of program storage space. Maximum is 28672 bytes.
  Global variables use 301 bytes (11%) of dynamic memory, leaving 2259 bytes for local variables. Maximum is 2560 bytes.

That is a saving of nearly 300 bytes code memory.

Notes:
1)
I don’t have a Trinket, hence the compile for a pro micro.
2)
Only for demo to show how you might be able to optimise.
3)
It should behave the same as your code that I stripped, but not tested.

Hello and thank you for your answers

I'm not calling the function yet, in fact since I thought I couldn't do the rest with the remaining space I focused on finding a solution, but with no big success

Thank you for taking the time to try and find something !
This is shorter than my own solution, I'll check if it's working as soon as I can and if I have the space, I'll do it with the rest of the strips.

It seems the Else If condition you wrote is the same as the one above, are the symbols the wrong way or is there something I didn't get ?

Copy/paste error :-[ The second 70 should have been 140. Not sure how it affects the size of the code.

I see, no worries !

I don't think it would work though, because there is no mention of the "vitesse" decreasing.

I know it's sort of weird, but I named it so "vitesse" would be representative of the speed at which the led gains intensity (A speed of 10 ads 10/255 everytime the loop goes back), so in order for it to decrease in intensity, the speed must go down.

Modifying this code might make it heavier in the end, don't you think ?

Thank you for your answer !