Some Neopixel examples

This example takes the Wemos Mini Ws2812B example a bit further on and use an 8 LED Neopixel strip

Here is an image of the strip we used

neopixel

Layout

A simple connection required for this one, you connect 3v3 to 5v / Vcc of the strip, Gnd goes to Gnd and you need an I/O line to go to the DIN. I use D8 in the examples below.

Here is a layout to give you the idea

neopixel strip and wemos mini_bb

Code Examples

A couple of code examples

[codesyntax lang=”cpp”]

#include <Adafruit_NeoPixel.h>

#define PIN D8

//the Wemos WS2812B RGB shield has 1 LED connected to pin 2
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(8, PIN, NEO_GRB + NEO_KHZ800);


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

void loop() 
{
  int led;
  for(led=0; led <=8; led++)
  {
    setColor(led,255,0,0,100); //red
  }
  for(led=0; led <=8; led++)
  {
    setColor(led,0,255,255,100); //
  }
    for(led=0; led <=8; led++)
  {
    setColor(led,255,0,255,100); //
  }
}

//simple function which takes values for the red, green and blue led and also
//a delay
void setColor(int led, int redValue, int greenValue, int blueValue, int delayValue)
{
  pixels.setPixelColor(led, pixels.Color(redValue, greenValue, blueValue)); 
  pixels.show();
  delay(delayValue);
}

[/codesyntax]

 

And another example

[codesyntax lang=”cpp”]

#include <Adafruit_NeoPixel.h>

#define PIN D8

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(8, PIN, NEO_GRB + NEO_KHZ800);

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

void loop() 
{
  int led;
  for(led=0; led <=7; led++)
  {
    setColor(led,255,0,0,100); //red
  }
  for(led=0; led <=7; led++)
  {
    setColor(led,0,0,0,100); //switch them off
  }
}

//simple function which takes values for the red, green and blue led and also
//a delay
void setColor(int led, int redValue, int greenValue, int blueValue, int delayValue)
{
  pixels.setPixelColor(led, pixels.Color(redValue, greenValue, blueValue)); 
  pixels.show();
  delay(delayValue);
}

[/codesyntax]

 

a random color example

[codesyntax lang=”cpp”]

#include <Adafruit_NeoPixel.h>

#define PIN D8

//the Wemos WS2812B RGB shield has 1 LED connected to pin 2
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(8, PIN, NEO_GRB + NEO_KHZ800);


void setup() 
{
  pixels.begin(); // This initializes the NeoPixel library.
  randomSeed(analogRead(0));
}

void loop() 
{
  rndColor(100);
}

//simple function which takes values for the red, green and blue led and also
//a delay
void setColor(int led, int redValue, int greenValue, int blueValue, int delayValue)
{
  pixels.setPixelColor(led, pixels.Color(redValue, greenValue, blueValue)); 
  pixels.show();
  delay(delayValue);
}

void rndColor(int delayValue)
{
  int led = random(0,7);
  int redValue = random(0, 255);
  int greenValue = random(0, 255);
  int blueValue = random(0, 255);
  pixels.setPixelColor(led, pixels.Color(redValue, greenValue, blueValue)); 
  pixels.show();
  delay(delayValue);
}

[/codesyntax]

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here