Multiple float in, out functions at once

septillion:
Ahh, but they do flicker quick. Aka, what did I do wrong now :confused:

Cleaned it a bit, back to debug

#include <FadeLed.h>

//91 step sine table 0 = 0 degree, 90 = 90 degree
const flvar_t SineTable[91] PROGMEM = {
  0,  4,  9,  13,  18,  22,  27,  31,  35,  40,
44,  49,  53,  57,  62,  66,  70,  75,  79,  83,
87,  91,  96, 100, 104, 108, 112, 116, 120, 124,
127, 131, 135, 139, 143, 146, 150, 153, 157, 160,
164, 167, 171, 174, 177, 180, 183, 186, 190, 192,
195, 198, 201, 204, 206, 209, 211, 214, 216, 219,
221, 223, 225, 227, 229, 231, 233, 235, 236, 238,
240, 241, 243, 244, 245, 246, 247, 248, 249, 250,
251, 252, 253, 253, 254, 254, 254, 255, 255, 255,
255};

//Make FadeLed object with a sine lookup table of 91 (0 to 90 including)
FadeLed sines[3] = {{3, SineTable, 90}, {5, SineTable, 90}, {9, SineTable, 90}};
const byte NrSines = sizeof(sines)/sizeof(sines[0]);

void setup(){
  Serial.begin(115200);
 
  for(byte i = 0; i < NrSines; i++){
    sines[i].setTime(1000); //halve period, 0% to 90% or 90% to 0%
  }

//start the first
  sines[0].on();
}

void loop(){
  FadeLed::update();

for(byte i = 0; i < NrSines; i++){
    /*//for all but last (who has no next)
    if(i < (NrSines - 1)){
      //if >50% (45 degree) and next is not fading and is off
      if((sines[i].getCurrent() >= 45) && sines[i + 1].done() && (sines[i + 1].get() == 0)){
        sines[i + 1].on();
      }
    }
  */
    //if sin is 100% (90 degree), fade back down
    if(sines[i].done() && sines[i].get()){
      sines[i].off();
    }
  }
}



Does this fade the first led up and down once?



#include <FadeLed.h>

//91 step sine table 0 = 0 degree, 90 = 90 degree
const flvar_t SineTable[91] PROGMEM = {
  0,  4,  9,  13,  18,  22,  27,  31,  35,  40,
44,  49,  53,  57,  62,  66,  70,  75,  79,  83,
87,  91,  96, 100, 104, 108, 112, 116, 120, 124,
127, 131, 135, 139, 143, 146, 150, 153, 157, 160,
164, 167, 171, 174, 177, 180, 183, 186, 190, 192,
195, 198, 201, 204, 206, 209, 211, 214, 216, 219,
221, 223, 225, 227, 229, 231, 233, 235, 236, 238,
240, 241, 243, 244, 245, 246, 247, 248, 249, 250,
251, 252, 253, 253, 254, 254, 254, 255, 255, 255,
255};

//Make FadeLed object with a sine lookup table of 91 (0 to 90 including)
FadeLed sines[3] = {{3, SineTable, 90}, {5, SineTable, 90}, {9, SineTable, 90}};
const byte NrSines = sizeof(sines)/sizeof(sines[0]);

void setup(){
  Serial.begin(115200);
 
  for(byte i = 0; i < NrSines; i++){
    sines[i].setTime(1000); //halve period, 0% to 90% or 90% to 0%
  }

//start the first
  sines[0].on();
}

void loop(){
  FadeLed::update();

for(byte i = 0; i < NrSines; i++){
    //if sin is 100% (90 degree), fade back down
    if(sines[i].done() && sines[i].get()){
      sines[i].off();
    }
  }
 
 
  if((sines[0].getCurrent() >= 45) && sines[1].done() && (sines[1].get() == 0)){
    sines[1].on();
  }
}



And this?

First one fades the LED up then down.

Second one however fades the first one up and down but the second one starts midway through the first one :slight_smile:
Much better!