Work with WS2812b using <fastLED> library

here is a code i want to try

#include <FastLED.h>
#define LED_PIN     6
#define NUM_LEDS    8
#define BRIGHTNESS  51
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];

void setup() {
  delay( 3000 ); // power-up safety delay
  FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  FastLED.setBrightness(  BRIGHTNESS );
}

void loop() {
  for(int dot = 0; dot < NUM_LEDS; dot++) {
  leds[dot] = CRGB::Blue;
  FastLED.show();

  // clear this led for the next time around the loop
  leds[dot] = CRGB::Black;
  delay(30);
  }
}
}

this code make single color move trough all led, but i want a specific color on some led, led 1,2,3 blue 4,5,6 green 7,8 red. how to make the code? thanks before

An if statement inside your for-loop can do

if(dot == 3 || dot == 5)
{
    leds[dot] = CRGB::Red);
}
else
{
  leds[dot] = CRGB::Blue;
}

The || is a logic OR.

If you have a lot with different colours, you might want to use an array of colours and iterate through that.

Try this (I have not tested it):

#include <FastLED.h>
#define LED_PIN     6
#define NUM_LEDS    8
#define BRIGHTNESS  51
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
CRGB myColours[NUM_LEDS] = {
  CRGB::Blue,
  CRGB::Blue,
  CRGB::Blue,
  CRGB::Green,
  CRGB::Green,
  CRGB::Green,
  CRGB::Red,
  CRGB::Red
};

void setup() {
  delay( 3000 ); // power-up safety delay
  FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  FastLED.setBrightness(  BRIGHTNESS );
}

void loop() {
  for(int dot = 0; dot < NUM_LEDS; dot++) {
    leds[dot] = myColours[dot];
    FastLED.show();

    // clear this led for the next time around the loop
    leds[dot] = CRGB::Black;
    delay(30);
  }
}

But not a "conditional OR" which is an interesting concept used in shell scripting.

:+1: nice

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