1

I have connected 4 Grove - RGB LED (WS2813 Mini) to D2,D3,D4,D5 on Grove Base Shield V2.0 for Arduino. How can I control the brightness and color of each LED? At the moment I only know to activated one.

Code:

#include "Adafruit_NeoPixel.h"
#define PIN            2
#define NUMPIXELS      1 
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
  
void setup() {
  pixels.setBrightness(125);
  pixels.begin();  
}
 
void loop() {
    pixels.setPixelColor(1, pixels.Color(255,255,255));  
    pixels.show();  
}

Thanks

0

1 Answer 1

1

Here is one of the multiple ways possible to address the problem, Basically, use a for loop and iterate the first parameter setPixelColor function to address all the LEDs. Try experimenting here:

#include "Adafruit_NeoPixel.h"
#define PIN            2
#define NUMPIXELS      4
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  pixels.setBrightness(125);
  pixels.begin();
}

void loop()
{
  pixels.clear(); // Set all pixel colors to 'off'

  // The first NeoPixel in a strand is #0, second is 1, all the way up
  // to the count of pixels minus one.
  for (int i = 0; i < NUMPIXELS; i++) { // For each pixel...

    // pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255
    // Here we're using a moderately bright green color:
    pixels.setPixelColor(i, pixels.Color(0, random(0,255), 0));

    pixels.show();   // Send the updated pixel colors to the hardware.

    delay(100); // Pause before next pass through loop
  }
}

here is quick view:

enter image description here

Since you are using NeoPixels, here is a list of simulated examples. you can play with the code and make your own projects online.

4
  • 1
    Thanks but the simulation is wrong as I have 4 Grove - RGB LED (WS2813 Mini) (seeedstudio.com/Grove-RGB-LED-WS2813-Mini-p-4269.html ) connected to D2,D3,D4,D5 and I wish to control each one of them separately.
    – alirazi
    Jul 11, 2021 at 19:57
  • 1
    @alirazi And why would you need 4 pins for that? As I see it the WS2813 is just like the standard Neopixels (WS2811 or 12 I think). You can daisy chain them. That way you only need one pin, but you can still control each LED individually.
    – chrisl
    Jul 11, 2021 at 20:22
  • @chrisl You are right, but I wish to avoid soldering and extra wires.
    – alirazi
    Jul 11, 2021 at 20:32
  • github.com/FastLED/FastLED/wiki/Multiple-Controller-Examples you have a few examples for controlling multiple addressable LEDs
    – ArduinoFan
    Jul 12, 2021 at 9:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.