FastLED and WS2812

I'm trying to use a 60 WS2812 led ring with repeating patterns as follows

6 White led's rotating around the ring for 5 minutes
changing to 4 Red led's rotating around the ring at increasing speed for 10 seconds
Then the 60 led's flashing red 5 times
rinse and repeat

I'm at my wits end lol
can anybody help ?

Post your best effort at coding what you want, using code tags when you do

See How to get the best out of this forum

My latest adventure, butchering this code from Marc Miller.

It's somewhere close but the white led's pause at the end of each rotation and I've not worked out how to speed up the red led's rotation

// EVERY_N trigger timer and variable timer example
//
// Using EVERY_N with a timer check to always run "Event B" at
// a specific time after "Event A".
//
// Also, an example of using EVERY_N with a random variable time.
//
// Marc Miller,  May 2016
//---------------------------------------------------------------

#include "FastLED.h"
#define LED_TYPE WS2812
#define DATA_PIN 4
//#define CLOCK_PIN 13
#define NUM_LEDS 60
#define COLOR_ORDER RBG
#define BRIGHTNESS 96
CRGB leds[NUM_LEDS];

uint16_t timerA = 3000;  // How often to run Event A [milliseconds]
uint16_t timerB = 500;  // How long after A to run Event B [milliseconds]
boolean counterTriggered = 0;  // Event triggered? [1=true, 0=false]


//---------------------------------------------------------------
void setup() { 
 // Serial.begin(115200);  // Allows serial output (check baud rate)
  delay(1500);  // 3 second startup delay
  FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
  FastLED.setBrightness(BRIGHTNESS);
}

//---------------------------------------------------------------
void loop() {
  
  // Setting the amount of time for "triggerTimer".
  // You can name "triggerTimer" whatever you want.
  static CEveryNMilliseconds triggerTimer(timerB);
  
  EVERY_N_MILLISECONDS(timerA){
  EVERY_N_SECONDS_I( timingObj, 50)// delay for white
    // do Event A stuff
   for(int i=0;i<NUM_LEDS;i++){  
   leds[i-4].setRGB(0,0,0);
   leds[i].setRGB(0,0,255);
   FastLED.show();
   delay(90);
   
     }
//    counterTriggered = 1;  // Set to True
//    triggerTimer.reset();  // Start trigger timer

   FastLED.clear();

  }

EVERY_N_MILLISECONDS(timerA){
  EVERY_N_SECONDS_I( timingObj, 50)// delay for white
    // do Event A stuff
   for(int i=0;i<NUM_LEDS;i++){  
   leds[i-4].setRGB(0,0,0);
   leds[i].setRGB(0,0,255);
   FastLED.show();
   delay(60);
   
     }
   counterTriggered = 1;  // Set to True
   triggerTimer.reset();  // Start trigger timer

   FastLED.clear();

  }
  
  if (counterTriggered == 1) {  // Will only be True if Event A has started
    if (triggerTimer) {  // Check if triggerTimer time reached
//    EVERY_N_SECONDS_I( timingObj, 5) 
     // do Event B stuff
    for(int i=0;i<NUM_LEDS;i++){  
   leds[i-6].setRGB(0,0,0);
   leds[i].setRGB(255,255,255);
   FastLED.show();
   delay(80);

     }
//      counterTriggered = 0;  // Set back to False
//      triggerTimer.reset();  // Start trigger timer
    FastLED.clear();
     
          FastLED.clear();
      // delay(80);

       
    }
  }
/*

  EVERY_N_SECONDS_I( timingObj, 20) {
    // This initally defaults to 20 seconds, but then will change the run
    // period to a new random number of seconds from 10 and 30 seconds.
    // You can name "timingObj" whatever you want.
    timingObj.setPeriod( random8(10,31) );
    FastLED.clear();
    for (uint16_t i=0; i<NUM_LEDS*3; i++){
      leds[random8(NUM_LEDS)] = CRGB::Black;
      leds[random8(NUM_LEDS)] = CHSV(random8(), random8(140,255), random8(50,255));
      FastLED.show();
      delay(random8(20,80));
    }

    delay(500);
  }
*/

//  FastLED.show();
 
}//end main loop

@chrisbircham Why do users choose to ignore the advice on posting code ?

The easier you make it to read and copy your code the more likely it is that you will get help

Please follow the advice given in the link below when posting code , use code tags and post the code here

    for (int i = 0; i < NUM_LEDS; i++)
    {
      leds[i - 4].setRGB(0, 0, 0);

When i equals 0 which LED will be affected by this ?

oops

More to the point, which memory location outside of the array will be written to ?

Try:

leds[(i + NUM_LEDS - 4) % NUM_LEDS].setRGB(0, 0, 0);

OK, so coding aside, what is the purpose of this display? :astonished:

People want to know. :laughing:

Paul
It's for inside the Star Wars Interrogation droid
lol

Thanks guys
I have it almost working now using Neopixel.h instead.
Just need to sort out the timer for the white led routine. (5 minutes)

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