Back to Parent

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

#define PIXEL_PIN D2
#define PIXEL_COUNT 28
#define PIXEL_TYPE WS2812
 
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
 
 
void setup() {
    strip.begin();
    strip.show();
 
    Particle.subscribe("toggle-led-bat", toggleBat, MY_DEVICES);
    Particle.subscribe("toggle-led-bed", toggleBed, MY_DEVICES);
}
 
void loop() {
    uint32_t c = strip.Color(0, 0, 0);
    for( int i = 0; i < strip.numPixels(); i++ ) {
        strip.setPixelColor(i, c); // set a color
       
    }
    strip.show();
    delay(10);
}
 
void toggleBat(const char *event, const char *data) {
    uint32_t c = strip.Color(255, 0, 0);
    for(int i = 1; i < strip.numPixels()-1; i = i+2) {
        strip.setPixelColor(i, c); // set a color
    }
    strip.show();
    delay(1000);
    Serial.println("rece");
}
 
void toggleBed(const char *event, const char *data) {
    uint32_t c = strip.Color(0, 0, 255);
    for(int i = 0; i < strip.numPixels(); i = i+2) {
        strip.setPixelColor(i, c); // set a color
    }
    strip.show();
    delay(1000);
    Serial.println("rece2");
}
Click to Expand

Content Rating

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

0