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 light_ring = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

int brightness = 0;
unsigned long timeAtParticleFunction = 0;
unsigned long timeFade = 30*1000;

bool lightStatus = false;

void setup() {

  light_ring.begin();
  light_ring.show(); 
  
  Particle.function("sync-on",turnOn);
  Particle.function("sync-off",turnOff);

}


int turnOn(String command)
{
    lightStatus = true;
    timeAtParticleFunction = millis();
    return 0;
}


int turnOff(String command)
{
    lightStatus = false;
    timeAtParticleFunction = millis();
    return 0;
}


void loop(){
    
    if(lightStatus == true){
        
        // for(int i=0; i<light_ring.numPixels(); i++){
        //     light_ring.setPixelColor(i,255,0,0); //red
    
        // }
        
        // light_ring.show();
        unsigned long timeNow = millis();
        
        if(  timeAtParticleFunction + timeFade < timeNow ){
            // lightStatus = false;
            
            // this will step up the brightness from 255 to 0
            for( int brightness = 255; brightness > 0; brightness++ ){
                // loop over each led and set the brightness 
                for( int i = 0; i < light_ring.numPixels(); i++ ){
                    light_ring.setPixelColor( i, brightness, 0 , 0 );
                }
                light_ring.show();
                delay( 100 );
            }
        }
        
        
    }else{
        
        for(int i=0; i<light_ring.numPixels(); i++){
            light_ring.setPixelColor(i,255,255,255); //white
        }
        light_ring.show();
        

    }
    
}
Click to Expand

Content Rating

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

0