Skills Dev III: Ambient Orb PGT

Made by pgomezte

Work with NeoPixels and build connectivity via Google Calendar to change the ambient of the lights based on updates.

Created: November 30th, 2022

0

Goal:

The objective of this project is to start working with NeoPixels, build codes to light them up in different ways, and finally, to connect your Particle device to your Google Calendar through IFTTT and display an alert using a Neopixel LED array

0

The first part of this assignment is to practice using the NeoPixels in my Particle kit. Once I built the circuit with the required connections, I will attempt to light the neopixel with different lights to practice. See video and code below with a quick demo.

Note: the code immediatley below was built to help me practice with NeoPixels

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

#define PIXEL_PIN D2
#define PIXEL_COUNT 8
#define PIXEL_TYPE WS2812

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

int turnRed(String command) {
    return 1;
}

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

}

void loop() {
    
    // Exercise 2
    
    uint16_t i;
    uint32_t cBlue = strip.Color(0, 0, 255);
    uint32_t cRed = strip.Color(255, 0, 0);
    uint32_t cGreen = strip.Color(0, 255, 0);
    uint32_t cWhite = strip.Color(255, 255, 255);
    uint32_t cPeach = strip.Color(200, 50, 0);
    uint32_t cCyan = strip.Color(10, 150, 70);
    uint32_t cPurple = strip.Color(180, 3, 180);
    uint32_t cOff = strip.Color(0,0,0);

    for(i=0; i<strip.numPixels(); i++) {
        strip.setPixelColor(i, cBlue);
		strip.show();
		delay(100);
    }
    
    for(i=0; i<strip.numPixels(); i++) {
        strip.setPixelColor(i, cRed);
        strip.show();
        delay(100);
    }
    
    for(i=0; i<strip.numPixels(); i++) {
        strip.setPixelColor(i, cGreen);
        strip.show();
        delay(100);
    }
    
    for(i=0; i<strip.numPixels(); i++) {
        strip.setPixelColor(i, cWhite);
        strip.show();
        delay(100);
    }

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

    for(i=0; i<strip.numPixels(); i++) {
        strip.setPixelColor(i, cPurple);
        strip.show();
        delay(100);
    }
    
}
Click to Expand
0
0

Now that I was able to practice with neopixels and figure out how to light them with different colors at different stages, I will now attempt for the lights to provide an alert when an event happens in Google Calendar (using IFTTT).

The first thing to do is setup IFTTT such that it can connect Google Calendar to  my Particle. The final product of this step is shown below.

0

I worked in class with the help of colleagues, and I was able to build a code that allows for the LED neopixel light to light up differently based on a Google Calendar alert through IFTTT.

Unfortunately, this never worked on my device, but I am sure everything in the code works, it is just that my device is not optimally wired.

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

//Set pixel COUNT, PIN, and TYPE 
#define PIXEL_COUNT 8
#define PIXEL_PIN D2
#define PIXEL_TYPE WS2812

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


int cRed = 25;        //to track the value of Red color
int cGreen = 25;        //to track the value of Green color
int cBlue = 25;        //to track the value of Blue color

bool calAlert_Status = false;       //to check if the calender alert occured
unsigned long lastUpdate;       //to check track the time usin millis()
unsigned long now =0;           //to check track the time usin millis()

void setup() {

    strip.begin();
    strip.show();   //Initialize all pixels to 'off'
    
    //Particle function on cloud
    Particle.function("Cal_Alert", setCalAlert);
    
    //Switch on each pixel all at once with cool white color
    for(int i=0; i<strip.numPixels(); i++){
        strip.setPixelColor( i, cRed, cGreen, cBlue);
    }
    strip.show();

}

void loop() {
    
    
    if (calAlert_Status == true){
        //Fade to red
        now = millis();
        if ((now - lastUpdate) <= 900000){
            
            cRed = map((now - lastUpdate), 0, 900000, 20, 255); 
            cGreen = map((now - lastUpdate), 0, 900000, 0, 25); 
            cBlue = map((now - lastUpdate), 0, 900000, 0, 25); 
            if(cGreen<0){
                cGreen = 0;
                cBlue = 0;
            }
            
            if (cRed <= 255) {
                for(int i=0; i<strip.numPixels(); i++){
                   strip.setPixelColor( i, cRed, (25-cGreen), (25-cBlue));
                }
                strip.show();
            }
        }
        else{
     
           calAlert_Status = false; 
           Particle.publish("MeetingStarted-FadingtoWhite");    ////publishing meeting notification in cloud
        }
    }
    else{
        //Back to cool white
        now = millis();
        if (((now - lastUpdate) >= 900000) && ((now - lastUpdate) <= 1800000)){
            
            cRed = map((now - lastUpdate), 900000, 1800000, 0, 230); 
            cGreen = map((now - lastUpdate), 900000, 1800000, 0, 25); 
            cBlue = map((now - lastUpdate), 900000, 1800000, 0, 25); 
            
            if (cRed > 25){
                for(int i=0; i<strip.numPixels(); i++){
                   strip.setPixelColor( i, (255-cRed), cGreen, cBlue);
                }
                strip.show();
            }
        }
        
    }
}


//Function to get calendar alert from IFTTT through cloud
int setCalAlert(String command){
    
    if(command == "True") {
        calAlert_Status = true;
        lastUpdate = millis();
        Particle.publish("CalenderAlert-FadingtoRed");      //publishing alert received on cloud
        return 1;
    }
    return -1;
}
Click to Expand
x
Share this Project


About

Work with NeoPixels and build connectivity via Google Calendar to change the ambient of the lights based on updates.