Back to Parent

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

bool meetingStatus = false;
bool redOn = false;

unsigned long timeAtStart = 0;
unsigned long timeToFade = (60*15000); //15 minutes

float redVal = 255.0;
float greenVal = 255.0;
float blueVal = 255.0;

void setup() {

  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  
  Particle.function("meeting_soon", meetingSoon);
}

int meetingSoon(String arg){
    
    timeAtStart = millis();
    if (arg == "yes"){
        meetingStatus = true;
    } else if (arg == "no") {
        meetingStatus = false;
    }
    return 0;
}

void loop() {

  uint32_t white = strip.Color(255, 255, 255); // White
  uint32_t red = strip.Color(255, 0, 0); // red
  uint32_t currentColor;

  if (meetingStatus == true) {
      
    unsigned long now = millis();
    
    while (now - timeAtStart <= timeToFade){
        now = millis();
        greenVal -= (255/60);
        blueVal -= (255/60);
        currentColor = strip.Color(255, greenVal, blueVal);
        for( int i=0; i< strip.numPixels(); i++) {
            strip.setPixelColor(i, currentColor);
            strip.setBrightness(20);
        }
        strip.show();
        delay(15000);
    }
    redOn = true;

  }else if (meetingStatus == false && redOn == true){
    greenVal = 0.0;
    blueVal = 0.0;
    
    unsigned long now = millis();
    
    while (now - timeAtStart <= timeToFade){
        now = millis();
        greenVal += (255/60);
        blueVal += (255/60);
        currentColor = strip.Color(255, greenVal, blueVal);
        for( int i=0; i< strip.numPixels(); i++) {
            strip.setPixelColor(i, currentColor);
            strip.setBrightness(20);
        }
        strip.show();
        delay(15000);
    }
    redOn = false;
  
  
  } else {
      
    for( int i=0; i< strip.numPixels(); i++) {
        strip.setPixelColor(i, white);
        strip.setBrightness(20);
    }
    strip.show();
    delay( 100 );
    
    redOn = false;
      
  }
  

}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0