Skill Dev III(connect NeoPixel to IFTTT and Google calendar)

Made by Sohyun Jin ·

Making an Ambient Calendar Alert

Created: November 15th, 2023

0

  • This week, I worked on connecting NeoPixel to Google Calenda using IFTTT. I prompted NeoPixel to be connected to the current time (millis()) and use the minimum loops within the loop() function, enabling smooth fade-up and fade-out effects. I learned to list particle.function with keywords (e.g., fadeUp) and my token account in IFTTT to make NeoPixel behave according to the specified rules when Google Calendar triggers the action.
  • The most challenging part was verifying if it operates as set in the calendar.
  • (1) Occasionally, the particle console button would stop while being inactive, and I only figured out waiting or resetting as methods to reactivate it.
  • (2) Waiting for 3-10 minutes for each calendar setting was necessary, and understanding how the IFTTT real-time applet button functions was confusing me. Pressing this button sometimes seemed to trigger the NeoPixel to turn on, but it wasn't consistent. With TA Zhenfang's assistance, I adjusted the time more than at 18 minutes ahead, for setting 15-minute-ahead alerm on IFTTT. After waiting for about 18-22 minutes, in most cases, I confirmed that it reliably operates as intended.

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


//Important
#define PIXEL_PIN D2
#define PIXEL_COUNT 16
#define PIXEL_TYPE WS2812

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


int durationOfFade = 10000; //* 60 * 5;
int durationOfTransition = 20000; //* 60 * 10;
int durationOfOut = 10000; //* 60 * 5; 

//int durationFadeOut = 10000;

int maxLight = 200;

long timeStartedAt = -1; //when the action happens
bool timerStarter = false;
long fadeUpValue = 1;


void setup() {

    strip.begin();
    strip.show();
    Serial.begin(9600);
    
    Particle.function( "fadeUp", handleFadeUp );
    Particle.function( "stopNotication", handleStopNoti);
    
}

void loop() {
    
    // buttonState = digitalRead ( buttonPin ); //get the value 

    // if( buttonState == LOW ){

    //     if( timerStarter  == false ){
            
    //         timerStarter = true;
            
    //     } else {
        
    //         timerStarter  = false;
        
    //     }
    // }
    
    if( timerStarter == true ){
        
        long timeNow = millis();
        
        long timeElapsed = timeNow - timeStartedAt;
        
        if( timeElapsed < durationOfFade ){
            
            int colorValue = map( timeElapsed, 0, durationOfFade, 0,  maxLight );
            
            int r = 0;
            int g = colorValue;
            int b = 0;
            
            for( int i = 0; i < strip.numPixels(); i++ ){
                
                strip.setPixelColor(i, r, g, b);
                
            }
            
            
            Serial.print(timeElapsed);
            Serial.print("      ");
            Serial.println("phase1");
            
            strip.show();
                
        } else if( timeElapsed > durationOfFade and timeElapsed < (durationOfFade + durationOfTransition/2) ){
        
            int colorMap = timeElapsed - durationOfFade;  
            int colorValue1 = map( colorMap, 0, durationOfTransition/2, maxLight, 0);
            int colorValue2 = 0; //map( colorMap, 0, durationOfTransition/2, 0, 10);
            
            int r = colorValue2;
            int g = colorValue1;
            int b = 0;
            
            for( int i = 0; i < strip.numPixels(); i++ ){
                
                strip.setPixelColor(i, r, g, b);    
                
            }
            
            Serial.print(timeElapsed);
            Serial.print("      ");
            Serial.println("phase2");
            
            strip.show();
                
        } else if( timeElapsed > (durationOfFade + durationOfTransition/2) and timeElapsed < (durationOfFade + durationOfTransition) ){
        
            int colorMap = timeElapsed - (durationOfFade + durationOfTransition/2);  
            int colorValue2 = map( colorMap, 0, durationOfTransition/2,  0, maxLight);
            
            int r = colorValue2;
            int g = 0;
            int b = 0;
            
            for( int i = 0; i < strip.numPixels(); i++ ){
                
                strip.setPixelColor(i, r, g, b);    
                
            }
            
            Serial.print(timeElapsed);
            Serial.print("      ");
            Serial.println("phase3");
            
            strip.show();
                
        } else if ( timeElapsed > (durationOfFade + durationOfTransition) and timeElapsed < (durationOfFade + durationOfTransition + durationOfOut)){
            
            int colorMap = timeElapsed - (durationOfFade + durationOfTransition);  
            int colorValue = map( colorMap, 0, durationOfOut,  maxLight, 0);
            
            int r = colorValue;
            int g = 0;
            int b = 0;
            
            for( int i = 0; i < strip.numPixels(); i++ ){
                
                strip.setPixelColor(i, r, g, b);   
                
            }  
            
            Serial.print(timeElapsed);
            Serial.print("      ");
            Serial.println("phase4");
            
            strip.show();
            
        } else {
            
            timerStarter = false;
            
        }  
            
    } else {
      
        int r = 0;
        int g = 0;
        int b = 0;
        
        for( int i = 0; i < strip.numPixels(); i++ ){
            
            strip.setPixelColor(i, r, g, b);    
            
        }
        strip.show();
    }
    

    
    delay( 500 );  
        
}


int handleFadeUp( String cmd ){
        
    timeStartedAt = millis();
    timerStarter = true;

    return fadeUpValue; 
}

int handleStopNoti( String cmd ){
    
    timerStarter = false;
    fadeUpValue = 0;

    return 1; 
}
Click to Expand
0

  • I attached the wiring image below.  ( Please expand the video window to view.)

0
x
Share this Project

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


Courses

48-675 Designing for the Internet of Things

· 11 members

A hands-on introductory course exploring the Internet of Things and connected product experiences.


About

Making an Ambient Calendar Alert