WS2812B RGB SHIELD for WeMos D1 mini examples

In this example we look at a new wemos shield (for us anyway), this is called the RGB shield and as you might expect contains RGB leds, in fact it has 7 of these LEDs

7 RGB LEDs (WS2812B-mini) each with 24-bit RGB color

Not a lot to say about this other than lets look at some examples

Code

You need to add the Adafruit Neopixel library for these examples, there are other libraries you can try of course –

Example 1

[codesyntax lang=”cpp”]

#include <Adafruit_NeoPixel.h>

#define PIN   D4
#define LED_NUM 7

// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
Adafruit_NeoPixel leds = Adafruit_NeoPixel(LED_NUM, PIN, NEO_GRB + NEO_KHZ800);


void setup() 
{
  leds.begin(); // This initializes the NeoPixel library.
}



void led_set(uint8 R, uint8 G, uint8 B) 
{
  for (int i = 0; i < LED_NUM; i++) 
  {
    leds.setPixelColor(i, leds.Color(R, G, B));
    leds.show();
    delay(150);
  }
}

void loop() {

  led_set(10, 0, 0);//red
  led_set(0, 0, 0);

  led_set(0, 10, 0);//green
  led_set(0, 0, 0);

  led_set(0, 0, 10);//blue
  led_set(0, 0, 0);

}

[/codesyntax]

 

Example 2

[codesyntax lang=”cpp”]

#include <Adafruit_NeoPixel.h>

#define PIN   D4
#define LED_NUM 7

// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
Adafruit_NeoPixel leds = Adafruit_NeoPixel(LED_NUM, PIN, NEO_GRB + NEO_KHZ800);


void setup() 
{
  leds.begin(); // This initializes the NeoPixel library.
}



void loop() 
{
  for (int i = 0; i < LED_NUM; i++) 
  {
  leds.setPixelColor(i, leds.Color(10, 0, 0));
  leds.show();
  delay(250);

  leds.setPixelColor(i, leds.Color(0, 10, 0));
  leds.show();
  delay(250);

  leds.setPixelColor(i, leds.Color(0, 0, 10));
  leds.show();
  delay(250);
  }
}

[/codesyntax]

 

Example 3

My favourite this one

[codesyntax lang=”cpp”]

#include <Adafruit_NeoPixel.h>

#define PIN   D4
#define LED_NUM 7

// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
Adafruit_NeoPixel leds = Adafruit_NeoPixel(LED_NUM, PIN, NEO_GRB + NEO_KHZ800);


void setup() 
{
  leds.begin(); // This initializes the NeoPixel library.
  Serial.begin(9600);
  randomSeed(analogRead(A0));
}


void loop() 
{
  //you can make the colours 255 but that is bright
  int redRandom = random(10);
  int greenRandom = random(10);
  int blueRandom = random(10);
  int ledRandom = random(7);
  leds.setPixelColor(ledRandom, leds.Color(redRandom, greenRandom, blueRandom));
  leds.show();
  delay(250);
}

[/codesyntax]

There are other examples in the Neopixel libarry which you can try and adapt as well

Buy it from Wemos at https://www.aliexpress.com/store/product/WS2812B-RGB-SHIELD-for-WeMos-D1-mini/1331105_32666803472.html

LEAVE A REPLY

Please enter your comment!
Please enter your name here