WS2812B Programming Help

Salutations! I am trying to program a WS2812B with 64 leds. What I want to do is have the lights light up one at a time, in a chase effect; once they are all lit up, have them all blink a couple times; then stay on. Haven't decided on colors yet, but I will play around with that. I am looking for suggestions so I can do more with less lines of code. So far I have been experimenting with code to get the hang of it. Here is what I have at the moment:

#include <FastLED.h>
#define LED_PIN     7
#define NUM_LEDS    20
CRGB leds[NUM_LEDS];
void setup() {
  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  
}
void loop() {
  
  leds[0] = CRGB(255, 0, 0);
  FastLED.show();
  delay(500);  
  leds[1] = CRGB(0, 255, 0);
  FastLED.show();
  delay(500);
  leds[2] = CRGB(0, 0, 255);
  FastLED.show();
  delay(500);
  leds[5] = CRGB(150, 0, 255);
  FastLED.show();
  delay(500);
  leds[9] = CRGB(255, 200, 20);
  FastLED.show();
  delay(500);
  leds[14] = CRGB(85, 60, 180);
  FastLED.show();
  delay(500);
  leds[19] = CRGB(50, 255, 20);
  FastLED.show();
  delay(500);
}/code]

It appears you have just copied someone’s sketch.

For example, NUM_LEDS 20 this should be NUM_LEDS 64

You should learn to use a ‘for()’ loop.

You should avoid using ‘delay()’, in place use millis() timing techniques.

What does you wiring schematic look like?

that is sort of what I did, but again I was experimenting with the code to get the idea. Not really sure how to draw the schematic but it it simple, the matrix itself is controlled with only a Vin, Vout, and a data cable controlling all 64 leds. I will try the millis though, thank you. anyone got any other suggestions

For controlling ledstrip there are so many ways, personally i don't use FastLED, simply because it allows 'writing beyond the size of the array' but let's try and prevent that. Using millis90 there are 2 main methods, either wait until a moment since the last update has passed and take the next step, or take a 'zero-moment' value and keep calculating where you should be from that. I do the latter. We can start with doing a flash

#include <FastLED.h>
#define LED_PIN     7
#define NUM_LEDS    20
CRGB leds[NUM_LEDS];
void setup() {
  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
 
}

void loop() {
  PlaySequence(1);
}

void PlaySequence(uint8_t seq) {
  switch (seq) {
    case 1:
      FlashLeds(CRGB(255,0,0), 1000, false);
      break;
    case 2:
      FlashLeds(CRGB(255,0,0), 2000, true);
      break;
  }
}


void FlashLeds(CRGB col, uint32_t cycle, bool fade) {
  static uint32_t zeromoment=millis();
  uint32_t elapsed=millis()-zeromoment;
  elapsed=elapsed % cycle;
  if (fade) {
    float steplength=cycle/510;        
    uint16_t phase=(elapsed/steplength); 
    if (phase>255) phase = 510 - phase;    
    AllColor (SetLevel(col, phase));
  }
  else {
    cycle=cycle/2;
    if (elapsed/cycle) {
      AllColor(col);
    }
    else ClearLeds();
  }
  FastLED.show();
}

CRGB SetLevel(CRGB col, uint8_t level) {
  col.r = ((uint16_t) col.r * level) / 255;
  col.g = ((uint16_t) col.g * level) / 255;
  col.b = ((uint16_t) col.b * level) / 255;
  return col;
}

void AllColor(CRGB col) {
  for (uint8_t i=0; i<NUM_LEDS; i++) {
    leds[i]=col;
  }
}

void ClearLeds() {
  AllColor(CRGB (0,0,0));
}

I haven't used any of the included pattern (or brightness) function of FastLED simply because i think it is better to see how such a function can be used. The sketch is setup as non-blocking call to PlaySequence() The function FlashLeds does either a smooth flash or a hard flash. And the other 3 functions are "helper functions" that we may use in other functions as well. It compiles, but i haven't actually tested it, i don't have a setup here to do that instantly, and writing a bit of code takes time enough.