Back to Parent

// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>

// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>

// 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);
// Our button wired to D0
int switchPin = D3;
int brightness = 0;
int increment = 255;
int takePeriod = 3 * 1000;
// store the color changing state
bool change = false;


void setup(){

pinMode( switchPin , INPUT_PULLUP); // sets pin as input

strip.begin();

Particle.subscribe( "changeColor", handleColorChanging );
}

// store the brightness in a new variable

void loop(){
    int switchState = digitalRead( switchPin );
	if( switchState == LOW ){
        delay(takePeriod);
        uint32_t c = strip.Color(255,255,0); // yellow
        for( int i = 0; i < strip.numPixels(); i++ ){
            strip.setPixelColor(i, c); // set a color 
            }
        strip.show();
        if( change == true ){
            Particle.publish( "doPairedPublish" );
            delay(3000);
            changeColor();
        }
	}else{
	    uint32_t c = strip.Color(255,255,255); // white
        for( int i = 0; i < strip.numPixels(); i++ ){
            strip.setPixelColor(i, c); // set a color 
            }
        strip.show();
        change = false;
	}
}

void changeColor(){    //function to fade an LED

    uint32_t c = strip.Color(255,0,0); // red
    for( int i = 0; i < strip.numPixels(); i++ ){
        strip.setPixelColor(i, c); // set a color 
        }
    strip.show();

}

void handleColorChanging( const char *event, const char *data){
   change = true;
}
Click to Expand

Content Rating

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

0