Skill Dev III - Miley Hu

Made by Miley Hu

Created: November 13th, 2021

0

Outcome

For the final activity, I connected my Google Calendar events with Particle. Whenever a new event is created on my calendar, the function will be called to light up the NeoPixel.

0

Process

To get familiarized with NeoPixels, I worked through the NeoPixel tutorials first. 

0

Connecting the NeoPixels

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();
    
    uint32_t c = strip.Color(0, 0, 255); // Add a color
    for( int i = 0; i < strip.numPixels(); i++ ){
        strip.setPixelColor(i, c); // set a color 
    }
    
    strip.show(); // set updates to the strip
    delay(100);
}

void loop() {

}
Click to Expand
0

Exercise #1

Modify the code to light up pixel by pixel then reverse the sequence turning each pixel off one by one. 

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();
    
    uint32_t c1 = strip.Color(0, 255, 0);
    uint32_t c2 = strip.Color(0, 0, 0);
    
     int numPixels = strip.numPixels();
    
    for( int i = 0; i < numPixels; i++ ){
        strip.setPixelColor(i, c1); // set a color 
                
        strip.show(); // set updates to the strip
        delay(300); 
    }


    for( int i = numPixels; i >= 0; i-- ) {
        strip.setPixelColor(i, c2); // remove the color

        strip.show();
                
        delay(300);
    }
}
Click to Expand
0
Skill Dev 3 - Exercise 1
Miley Hu - https://youtu.be/0P_Rx69m8CQ
0

Exercise 2

Modify the code to light up blue, then red, then green then white in sequence

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();
    
    uint32_t blue = strip.Color(0, 0, 255);
    uint32_t red = strip.Color(255, 0, 0);
    uint32_t green = strip.Color(0, 255, 0);
    uint32_t white = strip.Color(255, 255, 255);
    uint32_t black = strip.Color(0, 0, 0);
    
    uint32_t colors[] = {blue, red, green, white};
    
    int numPixels = strip.numPixels();
    
    for (int j = 0; j < 4; j++) {
    
        for( int i = 0; i < numPixels; i++ ){
            strip.setPixelColor(i, colors[j]); // set a color 
                
        }
        
        strip.show(); // set updates to the strip
        delay(1500); 
        
        for( int i = numPixels; i >= 0; i-- ) {
            strip.setPixelColor(i, black); // remove the color
        }   
        strip.show();
        delay(500);
    }
    
}
Click to Expand
0
Skill Dev 3 - Exercise 2
Miley Hu - https://youtu.be/A-Sw8-fBDIE
0

Exercise #3

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.

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();

}

void loop() {
    uint32_t white = strip.Color(255, 255, 255);
    uint32_t black = strip.Color(0, 0, 0);
    
    int numPixels = strip.numPixels();
    
    for( int i = 0; i < numPixels; i++ ){
        strip.setPixelColor(i, white); // set a color 
        
        strip.show();
        delay(500);
        
        strip.setPixelColor(i, black); // remove the color
        strip.show();
        delay(500);
    }
}
Click to Expand
0
Skill Dev 3 - Exercise 3
Miley Hu - https://youtu.be/9h0c-cRXbAM
0

Exercise #4

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
#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();
    
    Particle.function("red", setRed);   
    Particle.function("blue",setBlue);   
    Particle.function("green", setGreen);   

}

void loop() {
    
}

int setRed(String value) {
    int v = value.toInt();
    uint32_t red = strip.Color(v, 0, 0);
    int numPixels = strip.numPixels();
    
    if (v >= 0 && v < 256) {
        for( int i = 0; i < numPixels; i++ ){
            strip.setPixelColor(i, red); // set a color 
        }
        
        strip.show();
        delay(500);
        
        return 1;
    } else {
        return -1;
    }
}

int setBlue(String value) {
    int v = value.toInt();
    uint32_t red = strip.Color(0, 0, v);
    int numPixels = strip.numPixels();
    
    if (v >= 0 && v < 256) {
        for( int i = 0; i < numPixels; i++ ){
            strip.setPixelColor(i, red); // set a color 
        }
        
        strip.show();
        delay(500);
        
        return 1;
    } else {
        return -1;
    }
}

int setGreen(String value) {
    int v = value.toInt();
    uint32_t red = strip.Color(0, v, 0);
    int numPixels = strip.numPixels();
    
    if (v >= 0 && v < 256) {
        for( int i = 0; i < numPixels; i++ ){
            strip.setPixelColor(i, red); // set a color 
        }
        
        strip.show();
        delay(500);
        
        return 1;
    } else {
        return -1;
    }
}
Click to Expand
0
Skill Dev 3: Exercise 4
Miley Hu - https://youtu.be/rYzLaK09ccA
x