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


bool doBlink = false;


// Our button wired to D3
int buttonPin = D3;

void setup()
{

  // For input, we define the
  // pushbutton as an input-pullup
  // this uses an internal pullup resistor
  // to manage consistent reads from the device

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

    strip.begin();
    strip.show(); // Initialize all pixels to 'off'
	
	// blink the LED when the setup is complete
    blinkNP();
    
    // subscribe to Donner
    Particle.subscribe( "Donner_to_Felicia", handleBlinkNP );


}

void loop()
{
  // find out if the button is pushed
  // or not by reading from it.
    int buttonState = digitalRead( buttonPin );
    // set up NP pixel num and color constants
    uint16_t i;
    // NP on - white
    uint32_t w = strip.Color(255, 255, 255);
    // NP off
    uint32_t b = strip.Color(0, 0, 0);

  // remember that we have wired the pushbutton to
  // ground and are using a pulldown resistor
  // that means, when the button is pushed,
  // we will get a LOW signal
  // when the button is not pushed we'll get a HIGH

  // let's use that to set our NP on or off

  if( buttonState == LOW )
  {
    // turn the NP On
    for(i=0; i< strip.numPixels(); i++) {
        strip.setPixelColor(i, w );
		strip.show();
		delay( 100 );
    }
    // publish event
    Particle.publish( "Felicia_to_Donner" );
    
  }else{
    // otherwise
    // turn the NP Off
    for(i=0; i< strip.numPixels(); i++) {
        strip.setPixelColor(i, b );
		strip.show();
		delay( 100 );
  }

  }
	delay( 100 );
	
	// blinking
	if( doBlink == true ){
    blinkNP();
    doBlink = false;
    }

}

void blinkNP(){
    
    // set up NP pixel num and color constants
    uint16_t i;
    // NP on - white
    uint32_t w = strip.Color(255, 255, 255);
    // NP off
    uint32_t b = strip.Color(0, 0, 0);
    

    
    for(i=0; i< strip.numPixels(); i++) {
    strip.setPixelColor(i, w );
	strip.show();
// 	delay( 100 );
    }
    
    delay(500);
        
    for(i=0; i< strip.numPixels(); i++) {
    strip.setPixelColor(i, b );
	strip.show();
    // delay( 100 );
    }
    
    delay(500);

}


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

Content Rating

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

0