Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!



Two effects that ru...
 
Share:
Notifications
Clear all

[Solved] Two effects that run after each other

2 Posts
2 Users
0 Reactions
3,026 Views
(@augustrizon-netwafer)
New Member
Joined: 7 years ago
Posts: 1
Topic starter  

I'm looking to combine two LED Effect scripts. 

1st effect = sparkle for a determined amount of time then stop. 

after the first effect stops, wait a determined amount of time then run;

2nd effect = strobe for a determined amount of time then stop

I have both codes but cant figure out how to combine them and how to handle the timing.. Any help would be appreciated.

Here is the Sparkle effect Script:

#include "FastLED.h"

#define LEDPIN 6

#define LED_TYPE NEOPIXEL

#define NUM_LEDS 450 // Number of RGB LEDs in the strand

#define BRIGHTNESS 5000

#define FRAMES_PER_SECOND 100 //higher equals faster

CRGB leds[NUM_LEDS];

 void setup() {

 // set up LED strip info

FastLED.addLeds<LED_TYPE,LEDPIN>(leds,NUM_LEDS).setCorrection(TypicalLEDStrip);

FastLED.setBrightness(BRIGHTNESS);

}

 void loop() {

fadeToBlackBy( leds, NUM_LEDS,3); //speed higher = faster

addGlitter(105); //lower equal faster

FastLED.show(); 

}

 void addGlitter( fract8 chanceOfGlitter) {

  if( random8() < chanceOfGlitter) {

    leds[ random16(NUM_LEDS) ] += CRGB::White;}

This is the Strobe effect Script:

#include "FastLED.h"

#define NUM_LEDS 450 

CRGB leds[NUM_LEDS];

#define PIN 6 

void setup1 ()

{

  FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );

}

// REPLACE FROM HERE

void loop1() { 

  // Slower:

  // Strobe(0xff, 0x77, 0x00, 10, 100, 1000);

  // Fast:

  Strobe(0xff, 0xff, 0xff, 10, 50, 1000);

}

void Strobe(byte red, byte green, byte blue, int StrobeCount, int FlashDelay, int EndPause){

  for(int j = 0; j < StrobeCount; j++) {

    setAll(red,green,blue);

    showStrip();

    delay(FlashDelay);

    setAll(0,0,0);

    showStrip();

    delay(FlashDelay);

  }

 

 delay(EndPause);

}

// REPLACE TO HERE

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();

}


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
 

Hi Augustrizon.netwafer,

Good question, and funny that your question coincides timing-wise with another question in the forum.

Timing can be a little challenging and in your setup I'd recommend looking in to Timer Interrupts. Since I do not have much experience with this, you may have to read up on it. Some useful links:

  1. Arduino website – Timer
  2. Robotshop Arduino 101
  3. Instructables.com Arduino Timer Interrupts
You won't find a cookie-cut answer there, but it will give you some info to get started.


   
ReplyQuote
Share: