IOT Holiday Lights

#include "application.h"
#include "neopixel/neopixel.h"

SYSTEM_MODE(AUTOMATIC);

// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN A5
#define PIXEL_COUNT 11
#define PIXEL_TYPE WS2812B

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

int show = 0;
int flash = 0;

void setup() 
{
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  Spark.function("led",ledToggle);
}
void loop() 
{
      switch (show) {
    case 0:    // your hand is nowhere near the sensor
      off();
      break;
    case 1:    // your hand is on the sensor
      rainbow(30);
      break;
    case 2:    // your hand is close to the sensor
      theaterChaseRainbow(700);
      break;
    case 3:    // your hand is a few inches from the sensor
      purple();
      break;
  }
  delay(1);        // delay in between reads for stability

}

int ledToggle(String command) {
    if (command=="off") {
        show = 0;
        return 0;
    } else if (command=="on"){
        show = 1;
        return 1;
    } else if (command=="chase"){
          show = 2;
          return 2;
    } else if (command=="purple"){
          show = 3;
          return 3;
    } else if (command.indexOf("today") & command.indexOf("wind")){
        int firstComma = command.indexOf(',');
        int secondComma = command.indexOf(',', firstComma + 1 );
        purple();
    }
  delay(1);        // delay in between reads for stability
}

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / (strip.numPixels()/3))+j) & 255));
    }
    strip.show();
    delay(wait);
  }
  //if (flash == 1){
   //  flash=0;
  //} else {
     // flash++;
 // }
  }
  
void purple() {
  uint16_t i;
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, strip.Color(100,0,100));
    }
    strip.show();
}
  
void off() {
  uint16_t i;
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, strip.Color(0,0,0));
    }
    strip.show();
}

//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
  for (int j=0; j < 256; j++) {     // cycle all 256 colors in the wheel
    for (int q=0; q < 2; q++) {
      for (int i=0; i < strip.numPixels(); i=i+2) {
        strip.setPixelColor(i+q, Wheel( ((i * 256 / (strip.numPixels()/2))+j) % 255));    //turn every third pixel on
      }
      strip.show();

      delay(wait);

      for (int i=0; i < strip.numPixels(); i=i+2) {
        strip.setPixelColor(i+q, 0);        //turn every third pixel off
      }
    }
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

Holiday lights_bb