Back to Parent

#include "neopixel.h"
#define PIXEL_PIN D2
#define PIXEL_COUNT 16
#define PIXEL_TYPE WS2812
 
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
int red = 0;
unsigned long lastFade = 0;
int redPercentage=255;
// bool goingRed = true;
int goingRed = 1;


void setup() {

  strip.begin();
  strip.show(); 
  Particle.function("Red", setRed);

}


void loop() {
    
    
	unsigned long now = millis();
    if(red == 1){
	    
	    if ((now - lastFade) >= 500) {
            if (goingRed == 1) {
    			redPercentage = redPercentage - 2.5; 
    // 			Particle.publish("It is going red now");
    			if(redPercentage <= 0){
    			    redPercentage = 0;
    			    goingRed = 0;
    			}
    		}
    		
    		else if(goingRed == 0) {
    		    redPercentage = redPercentage + 2.5;
    		  //  Particle.publish("It is going white now");
    		    if(redPercentage >= 255){
    		        redPercentage = 255;
    		        goingRed = 1;
    		        red = 0;
    		    }
    	    }
    	
            lastFade=now;
    
        }
        
	
    }
    
    for(uint16_t i=0; i < strip.numPixels(); i++) {
            strip.setPixelColor(i, 255, redPercentage, redPercentage);
    }
	
	strip.show();
}
	
  
int setRed(String command){
    int number = atoi(command);
    if(number == 1){
        red = 1;
    }
    return red;
}
Click to Expand

Content Rating

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

0