Back to Parent

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

// Include Particle Device OS APIs
#include <Particle.h>


#define PIXEL_PIN SPI
#define PIXEL_COUNT 8
#define PIXEL_TYPE WS2812B

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

void setup() {
  // Initialize the strip
  strip.begin();
  delay(200);  // Small delay for stabilization

  // Set all pixels to black at startup
  for (int i = 0; i < strip.numPixels(); i++) {
    strip.setPixelColor(i, 0, 0, 0);  // Set each pixel to black (off)
  }
  strip.show();

  // Register the cloud function
  Particle.function("calendarNotification", flashRedFaster);
}

void loop() {
  // If you want animations or continuous effects, add code here
}

// Function to flash red from slower to faster
int flashRedFaster(String command) {
  int delayTime = 500;  // Start with a delay of 500ms (half a second)

  // Loop to gradually decrease delay time, speeding up the flashes
  for (int j = 0; j < 10; j++) {  // Flash 10 times, increasing speed
    // Turn all pixels red
    for (int i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, 255, 0, 0);  // Set each pixel to red
    }
    strip.show();
    delay(delayTime);  // Delay for the current flash speed

    // Turn all pixels off
    for (int i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, 0, 0, 0);  // Set each pixel to black (off)
    }
    strip.show();
    delay(delayTime);  // Delay for the current flash speed

    // Decrease delay time to make flashes faster
    delayTime = max(50, delayTime - 50);  // Decrease delay, but not below 50ms
  }

  return 1;  // Return success
}
Click to Expand

Content Rating

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

0