// This #include statement was automatically added by the Particle IDE.
#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 r = 0;
int b = 0;
int g = 0;
long lastPublishedAt = 0;
int publishAfter = 100; //the initial delay
bool blueOn = false; //color for Lily = blue
void setup() {
strip.begin();
Particle.subscribe("diot2021blossomneopixel" , handleSharedEvent);
}
void loop() {
// strip.show(); neopixel strip is off in the beginning
uint16_t i;
uint32_t c = strip.Color(0, 0, 255); // color Blue
publishPixelon();
if (blueOn == true){
for( int i = 0; i < strip.numPixels(); i++ ){
strip.setPixelColor(i, c); // each pixel turning on blue one by one
strip.show();
delay( 200 );
}
for ( int i = 15; i > 0; i-- ){
strip.setPixelColor(i, c); // each pixel turning off one by one
strip.show();
delay( 200 );
}
blueOn = false;
}
delay (100);
}
void publishPixelon(){
if ( lastPublishedAt + publishAfter < millis() ){
String pixelOn = "diot2021blossomneopixel";
if(blueOn == false){
Particle.publish(pixelOn);
}
lastPublishedAt = millis();
}
}
void handleSharedEvent(const char *event, const char *data){
String pixelOn = String(event); // this is reading the function as per particle.publish, convert to a string object first
String deviceID = System.deviceID();
// device id =
// event being triggered = "diot2021blossomneopixel"
if( pixelOn.indexOf( deviceID) != -1 ){
return;
}
else{
blueOn = true;
}
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .