Back to Parent

// Include the Particle-compatible NeoPixel library
#include <neopixel.h>

// Set the pixel COUNT, PIN, and TYPE
#define PIXEL_PIN SPI // WIRE TO PIN MO
#define PIXEL_COUNT 8
#define PIXEL_TYPE WS2812B

Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

bool notificationActive = false; // Tracks if the notification is active
unsigned long notificationStart = 0;
unsigned long notificationDuration = 900000; // 15 minutes in milliseconds

int startNotification(String command) {
    notificationActive = true;
    notificationStart = millis();
    return 1; // Return success
}

void setup() {
    strip.begin();
    strip.show();
    Particle.function("startAlert", startNotification); // Cloud function
}

void loop() {
    if (notificationActive) {
        unsigned long elapsed = millis() - notificationStart;

        if (elapsed <= notificationDuration) {
            int brightness = map(elapsed, 0, notificationDuration, 0, 255);
            for (int i = 0; i < PIXEL_COUNT; i++) {
                strip.setPixelColor(i, strip.Color(brightness, 0, 0)); // Red fade
            }
            strip.show();
        } else {
            notificationActive = false; // Reset after duration
        }
    }
}
Click to Expand

Content Rating

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

0