Need help inserting a strobe effect into the beginning of an existing neopixle code

Greetings,

Making a super saiyen effect for a costume, so id like the neopixles I'm using to do a strobe effect when they first come on, then repeat a chase code indefinitely. I had c+ 20 years ago...but my coding is made of rust. lol

This is the code I found for the chase effect...I thought about just putting the strobe in setup, but it just made everything stop working.

#include <Adafruit_NeoPixel.h>
#define PIN 6
#define NUM_LEDS 60
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  RunningLights(0xff,0xff,0x00, 50);
}

void RunningLights(byte red, byte green, byte blue, int WaveDelay) {
  int Position=0;
 
  for(int j=0; j<NUM_LEDS*2; j++)
  {
      Position++; // = 0; //Position + Rate;
      for(int i=0; i<NUM_LEDS; i++) {
        // sine wave, 3 offset waves make a rainbow!
        //float level = sin(i+Position) * 127 + 128;
        //setPixel(i,level,0,0);
        //float level = sin(i+Position) * 127 + 128;
        setPixel(i,((sin(i+Position) * 127 + 128)/255)*red,
                   ((sin(i+Position) * 127 + 128)/255)*green,
                   ((sin(i+Position) * 127 + 128)/255)*blue);
      }
     
      showStrip();
      delay(WaveDelay);
  }
}

void showStrip() {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.show();
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   FastLED.show();
 #endif
}

void setPixel(int Pixel, byte red, byte green, byte blue) {
 #ifdef ADAFRUIT_NEOPIXEL_H
   // NeoPixel
   strip.setPixelColor(Pixel, strip.Color(red, green, blue));
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   leds[Pixel].r = red;
   leds[Pixel].g = green;
   leds[Pixel].b = blue;
 #endif
}

void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue);
  }
  showStrip();
}

video_2021-11-28T14.59.49_1

Does this do what you want? It compiles, blinks on-board LED but otherwise untested:

#include <Adafruit_NeoPixel.h>
#define PIN 6
#define NUM_LEDS 60
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);

const uint8_t pinLED = LED_BUILTIN;

enum eStates
{
    ST_STROBE = 0,
    ST_RUNNINGLIGHTS
};

enum eStrobeStates
{
    ST_OFF = 0,
    ST_ON  
};

uint32_t
    tStrobe;
uint32_t
    tNow;
        
void setup() 
{
    strip.begin();
    strip.show(); // Initialize all pixels to 'off'

    pinMode( pinLED, OUTPUT );
    tStrobe = millis();
    
}//setup

void loop() 
{
    static uint8_t
        state = ST_STROBE;
        
    tNow = millis();
    switch( state )
    {
        case    ST_STROBE:
            if( (tNow - tStrobe) >= 3000ul )
            {
                digitalWrite( pinLED, LOW );
                state = ST_RUNNINGLIGHTS;
            }//if
            else
                Strobe();
                
        break;

        case    ST_RUNNINGLIGHTS:
            RunningLights(0xff,0xff,0x00, 50);
            
        break;
        
    }//switch
    
}//loop

void Strobe( void )
{
    static uint8_t
        stateStrobe = ST_OFF;
    static uint32_t
        tStrb = 0ul,
        tDelay = 0ul;

    tNow = micros();
    switch( stateStrobe )
    {
        case    ST_OFF:
            if( (tNow - tStrb) >= tDelay )
            {
                tDelay = (unsigned long)random( 10000ul, 40000ul );
                tStrb = tNow;    
                setAll( 0xff, 0xff, 0xff );
                digitalWrite( pinLED, HIGH );
                stateStrobe = ST_ON; 
                
            }//if
            
        break;        

        case    ST_ON:
            if( (tNow - tStrb) >= tDelay )
            {
                tDelay = (unsigned long)random( 30000ul, 150000ul );
                tStrb = tNow;    
                setAll( 0x00, 0x00, 0x00 );
                digitalWrite( pinLED, LOW );
                stateStrobe = ST_OFF; 
                
            }//if
        
        break;
        
    }//switch
    
}//Strobe

void RunningLights(byte red, byte green, byte blue, int WaveDelay) 
{
    int Position=0;
    
    for(int j=0; j<NUM_LEDS*2; j++)
    {
        Position++; // = 0; //Position + Rate;
        for(int i=0; i<NUM_LEDS; i++) 
        {
            // sine wave, 3 offset waves make a rainbow!
            //float level = sin(i+Position) * 127 + 128;
            //setPixel(i,level,0,0);
            //float level = sin(i+Position) * 127 + 128;
            setPixel(i,((sin(i+Position) * 127 + 128)/255)*red,
            ((sin(i+Position) * 127 + 128)/255)*green,
            ((sin(i+Position) * 127 + 128)/255)*blue);
        }    
        
        showStrip();
        delay(WaveDelay);
    
    }
}

void showStrip() 
{
#ifdef ADAFRUIT_NEOPIXEL_H
    // NeoPixel
        strip.show();
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
    // FastLED
        FastLED.show();
#endif
}

void setPixel(int Pixel, byte red, byte green, byte blue) 
{
#ifdef ADAFRUIT_NEOPIXEL_H
    // NeoPixel
    strip.setPixelColor(Pixel, strip.Color(red, green, blue));
    
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
    // FastLED
    leds[Pixel].r = red;
    leds[Pixel].g = green;
    leds[Pixel].b = blue;
    
#endif
}

void setAll(byte red, byte green, byte blue) 
{
    for(int i = 0; i < NUM_LEDS; i++ ) 
    {
        setPixel(i, red, green, blue);
    }
    showStrip();
}

I can see the video, but please tell me in actual words what you want. Just saying "strobe" doesn't tell me anything.
Paul

@Blackfin It did! a few quick tweeks and it worked perfectly. Wasnt ready for the con, but that was an unrelated issue.

20211209_225839_1_1

1 Like

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