Skill Dev3 - Yang Bai

Made by yangb ·

skill-dev3

Created: December 19th, 2020

0

Intention

In this project, I will finally make a device connected with Google Calendar which will give me a reminder before new events.

0

Approach

exercise 1:

Light up pixel by pixel then reverse the sequence turning each pixel off one by one.

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

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

void loop() {
    
    // here is to light up the pixel one by one
    
    uint16_t i;
    uint32_t c = strip.Color(0, 0, 255); //blue

    for(i=0; i < strip.numPixels(); i++) {
        strip.setPixelColor(i, c );
		strip.show();
		delay( 100 );
    }
	
	delay( 100 );
	
	// here is to turn off the pixel one by one
	
	for(i=0; i < strip.numPixels(); i++) {
        strip.setPixelColor(i, 0 );
		strip.show();
		delay( 100 );
    }

	delay( 100 );

}
Click to Expand
0
0

exercise 2:

light up blue, then red, then green then white in sequence . 

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

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

void loop() {
    
    // here is to light up the pixel one by one
    
    uint16_t i;
    uint32_t c = strip.Color(0, 0, 255); //blue

    for(i=0; i < strip.numPixels(); i++) {
        strip.setPixelColor(i, c );
    }
    
	strip.show();
	delay( 1000 );
	
	c = strip.Color(255, 0, 0); //red
	for(i=0; i < strip.numPixels(); i++) {
        strip.setPixelColor(i, c );
    }
    
	strip.show();
	delay( 1000 );
	
	c = strip.Color(0, 255, 0); //green
	for(i=0; i < strip.numPixels(); i++) {
        strip.setPixelColor(i, c );
    }
    
	strip.show();
	delay( 1000 );
	
	c = strip.Color(255, 255, 255); //white
	for(i=0; i < strip.numPixels(); i++) {
        strip.setPixelColor(i, c );
    }
    
	strip.show();
	delay( 1000);

}
Click to Expand
0
0

Exercise3:

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  

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

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

void loop() {
    
    // here is to light up the pixel one by one
    
    uint16_t i;
    uint32_t c = strip.Color(0, 0, 255); //blue

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

}
Click to Expand
0
0

  Exercise4:  

 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
// 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 red = 0;
int green = 0;
int blue = 0;

void setup() {
    
    strip.begin();
    strip.show(); // Initialize all pixels to 'off'
    Particle.function("red", setRed);
    Particle.function("green", setGreen);
    Particle.function("blue", setBlue);
    
}

void loop() {
    
    uint16_t i;
    uint32_t c = strip.Color(red, green, blue); //set the color

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

int setRed(String cmd) {
    
    int redInput = cmd.toInt();
    if(redInput >= 0 and redInput <= 255){
        red = redInput;
    }else{
        return -1;
    }
    return 1;
}

int setGreen(String cmd) {
    
    int greenInput = cmd.toInt();
    if(greenInput >= 0 and greenInput <= 255){
        green = greenInput;
    }else{
        return -1;
    }
    return 1;
}

int setBlue(String cmd) {
    
    int blueInput = cmd.toInt();
    if(blueInput >= 0 and blueInput <= 255){
        blue = blueInput;
    }else{
        return -1;
    }
    return 1;
    
}
Click to Expand
0
0

  Finally, I connected my Particle device to Google Calendar through IFTTT and it will send me a pixel lighting signal to alert 15 minutes before an appointment. Before 15 mins, the light will be turned one by one.  And it will be turned off after the event starts.

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

long timeAtParticleFuction = 0;
long turnOffAfter = 15*60*1000;

bool lightOn = false;

void setup() {
    
    strip.begin();
    strip.show(); // Initialize all pixels to 'off'
    Particle.function("turnOn", turnOn );

}

int turnOn(String command)
{
   lightOn = true;
   timeAtParticleFuction = millis();
   return 0;
   
}


void loop() {
    
    uint16_t i;
    long timeNow = millis();
    
    if(lightOn == true){
        
        for(i=0; i< strip.numPixels(); i++) {
            //turn on the pixel one by one, as blue
            strip.setPixelColor(i, 0, 0, 255); //blue
            strip.show();
            delay(100);
            strip.setPixelColor(i, 0, 0, 0);
            strip.show();
            delay(100);
        }
		// turn off all the light when 0 min left
		if (timeAtParticleFuction + turnOffAfter < timeNow){
		    
		    lightOn = false;
		}
		
    }else{
        for(i=0; i< strip.numPixels(); i++) {
            strip.setPixelColor(i, 0, 0, 0);
        }
		    strip.show();
    }

}
Click to Expand
0
0

Reflection

From this project, I learnt how to use neopixels to create multiple sigals. I think it's quite useful when I want to represent different event status. Besides, IFTTT is a very useful platform to combine particle with other application. 

x
Share this Project

This project is only accessible by signed in users. Be considerate and think twice before sharing.


Courses

About

skill-dev3