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

int count = 0;

int redValue = 0; // Full brightness for an ANODE RGB LED is 0, and off 255

int greenValue = 0; // Full brightness for an ANODE RGB LED is 0, and off 255

int blueValue = 0; // Full brightness for an ANODE RGB LED is 0, and off 255</td>


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


void setup()
{
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'

  Particle.subscribe( "diot/2019/paired/qcyool7000" , handleSharedEvent );
//   Particle.variable ("publishCount", publishCount);

  neoPixelLight() ;
  
  Particle.variable("publishCount", count);

}

void loop()
{
    
}

// Our event handlde requires two bits of information

// This gives us:

// A character array that consists of the event name

// A character array that contains the data published in the event we're responding to.

void handleSharedEvent(const char *event, const char *data)
{
    // Now we're getting ALL events published using "db2018/paired/"

    // This includes events from this device.

    // So we need to ignore any events that we sent.


    // Let's check the event name

    String eventName = String( event ); // convert to a string object

    // This gives us access to a bunch of built in methods

    // Like indexOf()

    // Locates a character or String within another String.

    // By default, searches from the beginning of the String,

    // but can also start from a given index,

    // allowing for the locating of all instances of the character or String.

    // It Returns: The index of val within the String, or -1 if not found.


    // We can use this to check if our event name contains the

    // id of this device


    String deviceID = System.deviceID();

    // device id = 0123456789abcdef

    // event = "diot/2019/paired/0123456789abcdef"


    if( eventName.indexOf( deviceID ) != -1 ){
      // if we get anything other than -1

      // the event came from this device.

      // so stop doing stuff

      return;
    }
    
    // otherwise do your stuff to respond to

    // the paired device here


    //motorOn = true;

    count += 1;
    
    if (count > 5){
        neoPixelLight(); 
    }
}



void neoPixelLight() {
    uint16_t i;
    uint32_t off = strip.Color(0, 0, 0);
    uint32_t cyan = strip.Color(0, 255, 255); 

    for(i=0; i< strip.numPixels(); i++) {
        strip.setPixelColor(i, cyan);
		strip.show();
		delay( 100 );
    }
    
    for(i=0; i< strip.numPixels(); i++) {
        strip.setPixelColor(i, off);
		strip.show();
		delay( 100 );
    }
}
Click to Expand

Content Rating

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

0