Skills Dev III: Working with Neopixels and Light

Made by Peng Dou

Created: December 1st, 2022

-1

Outcome

    • Modify the code to light up pixel by pixel then reverse the sequence turning each pixel off one by one
    • Modify the code to light up blue, then red, then green then white in sequence
    • Change the code to only light up only one pixel at a time. With each loop move that pixel one position higher. When it reaches the final pixel, restart the sequence at zero i.e. build a single pixel that will continually cycle
    • Add three Particle.function to set the Red, Green and Blue components. Allow these values to be set from 0-255 and as they are set to change all of the pixels on the LED strip to that color.

0

Process

Tested NeoPixel in different ways. Including display in different patterns.

0

Reflection

Controlling NeoPixel is easy. Just need to take care of the pattern that is expected by the task.

0
// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>

// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D2
#define PIXEL_COUNT 16
#define PIXEL_TYPE WS2812

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

int setRed(String str) {
    int level = str.toInt();
    for(int i=0; i< strip.numPixels(); i++) {
    strip.setPixelColor(i, strip.Color(level, 0, 0));
    	strip.show();
    }
    return 1;
}

int setGreen(String str) {
    int level = str.toInt();
    for(int i=0; i< strip.numPixels(); i++) {
    strip.setPixelColor(i, strip.Color(0, level, 0));
    	strip.show();
    }
    return 1;
}

int setBlue(String str) {
    int level = str.toInt();
    for(int i=0; i< strip.numPixels(); i++) {
    strip.setPixelColor(i, strip.Color(0, 0, level));
    	strip.show();
    }
    return 1;
}



void setup() {
  strip.begin();
  strip.show();
  Particle.function("setRed", setRed);
  Particle.function("setGreen", setGreen);
  Particle.function("setBlue", setBlue);
}

void loop() {


}
Click to Expand
0
#include "neopixel.h"

// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D2
#define PIXEL_COUNT 16
#define PIXEL_TYPE WS2812

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

void setup() {

  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {

  uint16_t i;
  uint32_t c = strip.Color(255, 255, 255);

  for(i=0; i< strip.numPixels(); i++) {
    strip.setPixelColor(i, c );
		strip.show();
		delay( 100 );
  }
	
	delay( 100 );

}
Click to Expand
0
0
0
0
0
x