// This #include statement was automatically added by the Particle IDE.
#include "neopixel/neopixel.h"
SYSTEM_MODE(AUTOMATIC);
// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D2
#define PIXEL_COUNT 200
#define PIXEL_TYPE WS2812B
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
int ledState = 0;
void stripSetPixelColor(unsigned char red, unsigned char green, unsigned char blue)
{
uint16_t i;
for (int i = 0 ; i < strip.numPixels() ; i += 1 )
{
strip.setPixelColor(i, strip.Color(red,green,blue));
}
strip.show();
}
void redStrip(uint8_t wait)
{
stripSetPixelColor(255, 0, 0);
delay(wait);
}
void orangeStrip(uint8_t wait)
{
stripSetPixelColor(255,150,0);
delay(wait);
}
void yellowStrip(uint8_t wait)
{
stripSetPixelColor(255,255,0);
delay(wait);
}
void greenStrip(uint8_t wait)
{
stripSetPixelColor(0,255,0);
delay(wait);
}
void cyanStrip(uint8_t wait)
{
stripSetPixelColor(0,255,255);
delay(wait);
}
void blueStrip(uint8_t wait)
{
stripSetPixelColor(0,0,255);
delay(wait);
}
void purpleStrip(uint8_t wait)
{
stripSetPixelColor(255,0,255);
delay(wait);
}
void magentaStrip(uint8_t wait)
{
stripSetPixelColor(155,48,255);
delay(wait);
}
void pinkStrip(uint8_t wait)
{
stripSetPixelColor(255,0,150);
delay(wait);
}
void whiteStrip(uint8_t wait)
{
stripSetPixelColor(255,255,255);
delay(wait);
}
void off(uint8_t wait)
{
stripSetPixelColor(0,0,0);
delay(wait);
}
int ledColor(String command)
{
if(command == "White")
{
whiteStrip(20);
return 1;
}
else if(command == "Pink")
{
pinkStrip(20);
return 1;
}
else if(command == "Red")
{
redStrip(20);
return 1;
}
else if(command == "Orange")
{
orangeStrip(20);
return 1;
}
else if(command == "Yellow")
{
yellowStrip(20);
return 1;
}
else if(command == "Green")
{
greenStrip(20);
return 1;
}
else if(command == "Cyan")
{
cyanStrip(20);
return 1;
}
else if(command == "Blue")
{
blueStrip(20);
return 1;
}
else if(command == "Purple")
{
purpleStrip(20);
return 1;
}
else if(command == "Magenta")
{
magentaStrip(20);
return 1;
}
else if(command == "Off")
{
off(20);
return 1;
}
else return -1;
}
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
/* Set up particle function to recieve code for */
Particle.function("ledcolor", ledColor);
strip.setBrightness(100);
Particle.subscribe("lights_off", myHandler);
}
void loop() {
}
void myHandler(const char *event, const char *data)
{
/* Particle.subscribe handlers are void functions, which means they don't return anything.
They take two variables-- the name of your event, and any data that goes along with your event.
In this case, the event will be "buddy_unique_event_name" and the data will be "intact" or "broken"
Since the input here is a char, we can't do
data=="intact"
or
data=="broken"
chars just don't play that way. Instead we're going to strcmp(), which compares two chars.
If they are the same, strcmp will return 0.
*/
if (strcmp(data,"intact")==0) {
// if your buddy's beam is intact, then turn your board LED of
blueStrip(20);
}
else if (strcmp(data,"broken")==0) {
off(20);
}
}
Comments