Skill Dev III(connect NeoPixel to IFTTT and Google calendar)
Made by Sohyun Jin ·
Made by Sohyun Jin ·
Making an Ambient Calendar Alert
Created: November 15th, 2023
// 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
This project is only accessible by signed in users. Be considerate and think twice before sharing.
A hands-on introductory course exploring the Internet of Things and connected product experiences.
Making an Ambient Calendar Alert