Back to Parent

#include "neopixel.h"
#include <math.h>

// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D2
#define PIXEL_COUNT 16
#define PIXEL_TYPE WS2812




int LIGHTEST = 100;

int pixel_position = 0;

int delaytime;

int green = LIGHTEST;

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

void setup(){

  Serial.begin( 9600 );
  Particle.variable("Delay", &delaytime, INT);
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  bool success = Particle.function("funcKey", funcName);
  bool success1 = Particle.function("color", changeColor);
    
}

int changeColor(String request) {
    if (request.toInt() <= 10) {
        green = 0;
    }
    return 1;
}

// Cloud functions must return int and take one String
int funcName(String extra) {
    int de = extra.toInt();
    delaytime = de;
    return 0;
}



void loop(){

  for(int i=0; i< strip.numPixels(); i++) {
    uint32_t c;

    if( pixel_position >= i ){
      c = strip.Color(LIGHTEST*i/strip.numPixels(), green, LIGHTEST*(strip.numPixels() - i)/strip.numPixels());  // WheelPos * 3, 255 - WheelPos * 3, 0
    }else{
      c = strip.Color(0, 0, 0);
    }
    strip.setPixelColor(i, c );
  }
  strip.show();
  

  pixel_position++;
  if( pixel_position >= strip.numPixels() )
  {
    pixel_position = 0;
  }

  delay( delaytime );


}
Click to Expand

Content Rating

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

0