Neo pixel fade in and stop

Hello, im using an arduino nano and a neo pixel string to create a project. What i am trying to do is have an led fade in and then stay on once it has reached the brightest value for good.

The code I have created works with the fade in but it seems to loop. Any ideas how to fix this?

#include <Adafruit_NeoPixel.h>

class Strip
{
public:
  uint8_t   effect;
  uint8_t   effects;
  uint16_t  effStep;
  unsigned long effStart;
  Adafruit_NeoPixel strip;
  Strip(uint16_t leds, uint8_t pin, uint8_t toteffects, uint16_t striptype) : strip(leds, pin, striptype) {
    effect = -1;
    effects = toteffects;
    Reset();
  }
  void Reset(){
    effStep = 0;
    effect = (effect + 1) % effects;
    effStart = millis();
  }
};

struct Loop
{
  uint8_t currentChild;
  uint8_t childs;
  bool timeBased;
  uint16_t cycles;
  uint16_t currentTime;
  Loop(uint8_t totchilds, bool timebased, uint16_t tottime) {currentTime=0;currentChild=0;childs=totchilds;timeBased=timebased;cycles=tottime;}
};

Strip strip_0(1, 8, 1, NEO_GRB + NEO_KHZ800);
struct Loop strip0loop0(1, false, 1);

//[GLOBAL_VARIABLES]

void setup() {

  //Your setup here:

  strip_0.strip.begin();
}

void loop() {

  //Your code here:

  strips_loop();
}

void strips_loop() {
  if(strip0_loop0() & 0x01)
    strip_0.strip.show();
}

uint8_t strip0_loop0() {
  uint8_t ret = 0x00;
  switch(strip0loop0.currentChild) {
    case 0: 
           ret = strip0_loop0_eff0();break;
  }
  if(ret & 0x02) {
    ret &= 0xfd;
    if(strip0loop0.currentChild + 1 >= strip0loop0.childs) {
      strip0loop0.currentChild = 0;
      if(++strip0loop0.currentTime >= strip0loop0.cycles) {strip0loop0.currentTime = 0; ret |= 0x02;}
    }
    else {
      strip0loop0.currentChild++;
    }
  };
  return ret;
}

uint8_t strip0_loop0_eff0() {
    // Strip ID: 0 - Effect: Fade - LEDS: 1
    // Steps: 22.86046511627907 - Delay: 43
    // Colors: 2 (0.0.0, 255.0.0)
    // Options: duration=983, every=1, 
  if(millis() - strip_0.effStart < 43 * (strip_0.effStep)) return 0x00;
  uint8_t r,g,b;
  double e;
  e = (strip_0.effStep * 43) / (double)983;
  r = ( e ) * 255 + 0 * ( 1.0 - e );
  g = ( e ) * 0 + 0 * ( 1.0 - e );
  b = ( e ) * 0 + 0 * ( 1.0 - e );
  for(uint16_t j=0;j<1;j++) {
    if((j % 1) == 0)
      strip_0.strip.setPixelColor(j, r, g, b);
    else
      strip_0.strip.setPixelColor(j, 0, 0, 0);
  }
  if(strip_0.effStep >= 22.86046511627907) {strip_0.Reset(); return 0x03; }
  else strip_0.effStep++;
  return 0x01;
}


Your topic was MOVED to its current forum category as it is more suitable than the original

Because you created this code, which is very complex, you should have no difficulty changing it to work the way you want. Your programming skills are at an advanced level and you need no help from the forum.

2 Likes

this code was created with online neopixel effects generator so that is why i am having the problem

Call strips_loop from setup() and remove it from loop().

I was not aware of that, please post a link.

Can you use online neopixel effects generator to create the effect you want? Modifying code created by a machine is always difficult because machines do not generate code which is easy for humans to read.

I was not aware of that, please post a link.

I used this generator to create the code.

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