Back to Parent

#include "neopixel.h"

#define PIXEL_COUNT 24
#define PIXEL_PIN D1

#define PIXEL_TYPE WS2812B

#define PEACH 246,187,27
#define ORANGE 255,70,10
#define RED 255,0,0
#define BLUE 52,222,246
#define GREEN 125,246,49

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

int waitTime = 25;
//was 25
int i;
//int timepassed = 0;
//int inputPin = D0;
int ledPin = D0;
int ledState = LOW;
int potPin = A0;
int potReading = 0;

int calibrateTime = 10000;


void setup()
{
strip.begin();
strip.show();
//strip1.begin();
//strip1.show();

Particle.subscribe("justgotinbedmyhomie", inBedHandler);
Particle.subscribe("justgotoutofbedfool", outOfBedHandler);
Particle.subscribe("fallen", fallenHandler);
pinMode( ledPin, OUTPUT );
//pinMode(inputPin, INPUT);
}

void loop()
{

if(ledState == HIGH)
{
 setLED( HIGH );
 neopixelSpin();

}else{

 neopixelsOff();
 setLED( LOW );
}
//if(timepassed == 4)
//{
 //spin (RED);
//}
}

void neopixelSpin()
{
potReading = analogRead(potPin);
if ((potReading > 0) && (potReading < 1023.75))
{ spin (PEACH);
}
if((potReading > 1023.75) && (potReading < 2047.5))
{
  spin (ORANGE);
}
if((potReading > 2047.5) && (potReading < 3071.25))
{
  spin (GREEN);
}
if((potReading > 3071.25) && (potReading < 4095))
{
  spin (BLUE);
}
}

void neopixelsOff(){
for(i=0;i<PIXEL_COUNT; i++)
{
  strip.setPixelColor(i, 0,0 ,0 );
  //strip1.setPixelColor(i,0,0,0);
}
strip.show();
//strip1.show();
delay(waitTime);
}


void setLED( int state )
{
digitalWrite( ledPin, state );
}


void inBedHandler(const char *event, const char *data)
{
ledState = LOW;
}

void outOfBedHandler(const char *event, const char *data)
{
ledState = HIGH;
}

void spin(int R, int G, int B)
{
    for(i=0;i<PIXEL_COUNT; i++)
    {
    strip.setPixelColor(i, R,G,B);
    //strip1.setPixelColor(i,R,G,B);
    strip.show();
    //strip1.show();
    delay(waitTime);
    }

}
void fallenHandler(const char *event, const char *data)
{
for(int j =0; j<255;j++)
{ strip.setBrightness(j);
  for (int k=0; k< PIXEL_COUNT; k++)
  {
    strip.setPixelColor(k,52,222,246);
    strip.show();
    delay(waitTime);
  }
}
}
Click to Expand

Content Rating

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

0