Code
#include "neopixel.h"
#include <math.h>
// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D0
#define PIXEL_COUNT 50
#define PIXEL_TYPE WS2812
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
int shouldRun = 0
void setup()
{
Particle.subscribe("sleepstar/2p", myHandler);
strip.begin();
strip.show();
}
void loop()
{
if(shouldRun == 1) {
breathe1(50);
breathe2(50);
breathe3(50);
breathe4(50);
} else if (shouldRun == 0){
breathe5(50);
}
}
void myHandler(const char *event, const char *data)
{
String dataStr = String(data);
if( dataStr.equals( "run" )) {
shouldRun = 1;
}else if ( dataStr.equals( "stop" )){
shouldRun = 0;
}
}
float breathe1(uint8_t wait){
float val = (exp(sin(millis()/2000.0*M_PI+1)) - 0.36787944)*20.0 ; //108.0
uint16_t i;
uint32_t c = strip.Color(val, val, val);
int array[] = {14,41,24,49,22,10};
int a;
for(a=0; a<6; a++) {
i = array[a];
strip.setPixelColor(i, c );
}
strip.show();
delay (wait);
}
float breathe2(uint8_t wait){
float val = (exp(sin(millis()/10000.0*M_PI)) - 0.36787944)*10.0 ; //108.0
uint16_t i;
uint32_t c = strip.Color(val, val, val);
int array[] = {31,0,46,4,38,6,44,39,18,32,35,33,48,47,20};
int a;
for(a=0; a<15; a++) {
i = array[a];
strip.setPixelColor(i, c );
}
strip.show();
delay (wait);
}
float breathe3(uint8_t wait){
float val = (exp(sin(millis()/2000.0*M_PI+3)) - 0.36787944)*20.0 ; //108.0
uint16_t i;
uint32_t c = strip.Color(val, val, val);
int array[] = {36,45,2,43,28,37};
int a;
for(a=0; a<6; a++) {
i = array[a];
strip.setPixelColor(i, c );
}
strip.show();
delay (wait);
}
float breathe4(uint8_t wait){
float val = (exp(sin(millis()/20000.0*M_PI+1.2)) - 0.36787944)*20.0 ; //108.0
uint16_t i;
uint32_t c = strip.Color(val, val, val);
int array[] = {12,40,16,8,30,34,26,42};
int a;
for(a=0; a<8; a++) {
i = array[a];
strip.setPixelColor(i, c );
}
strip.show();
delay (wait);
}
float breathe5(uint8_t wait){
uint16_t i;
uint32_t c = strip.Color(0, 0, 0);
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, c );
}
strip.show();
delay (wait);
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .