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 8
#define PIXEL_TYPE WS2812

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


uint16_t i;
uint32_t off = strip.Color(0, 0, 0);
uint32_t blue = strip.Color(0, 0, 255);
uint32_t red = strip.Color(255, 0, 0);
uint32_t green = strip.Color(0, 255, 0);
uint32_t white = strip.Color(255, 255, 255);

unsigned long lastFade = 0;

void setup() {
    //Register our Particle function here
    Particle.function("NPControl", NPControl);
    

    strip.begin();
    strip.show(); // Initialize all pixels to 'off'
    
    //Neopixel lights up when connected
	for(int j=0; j < strip.numPixels(); j++)
        {
        strip.setPixelColor(j, white);
        strip.show();
        delay(100);
        }
}

void loop() {
}

int NPControl(String command) {
    
    // find out the state of the LED
    int value = command.toInt();

    if( value > 0 ) {
        
        int gb = 255;
        
        // fade from white to red
        while (gb > 0) {
            
            gb -= 1;
            
            for(int j=0; j < strip.numPixels(); j++) {
                    strip.setPixelColor(j, 255, gb, gb);
                    strip.show();
                    }
            delay(30*1000/255); // current fade time is 30 seconds
        }
        
        // fade from red to white
        while (gb < 255) {
            
            gb += 1;
            
            for(int j=0; j < strip.numPixels(); j++) {
                    strip.setPixelColor(j, 255, gb, gb);
                    strip.show();
                    }
            delay(30*1000/255);// current fade time is 30 seconds
        }

	
    }
    
    else {
        return -1;
    }

    return 1;
}
Click to Expand

Content Rating

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

0