#include "neopixel.h"
// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_COUNT 24
#define PIXEL_PIN D2
#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 = D1;
int pirState = LOW;
int val = 0;
int calibrateTime = 10000;
void setup()
{
strip.begin();
strip.show();
Particle.subscribe("timepassed", myHandler, MY_DEVICES);
pinMode( ledPin, OUTPUT );
pinMode(inputPin, INPUT);
}
void loop()
{
if ( calibrated() )
{
readTheSensor();
reportTheData();
}
if(pirState == HIGH)
{
timepassed = 0;
}
if(timepassed == 0)
{
spin (BLUE);
}
if(timepassed == 1) // timepassed > 7 && timepassed < 15
{
spin (GREEN);
}
if(timepassed == 2)
{
spin (PEACH);
}
if(timepassed == 3)
{
spin (ORANGE);
}
if(timepassed == 4)
{
spin (RED);
}
}
void readTheSensor()
{
val = digitalRead(inputPin);
}
bool calibrated()
{
return millis() - calibrateTime > 0;
}
void reportTheData() {
if (val == HIGH)
{
if (pirState == LOW) {
Particle.publish("designingiot/s15/motion");
pirState = HIGH;
setLED( pirState );
}
} else {
if (pirState == HIGH) {
pirState = LOW;
setLED( pirState );
}
}
}
void setLED( int state )
{
digitalWrite( ledPin, state );
}
void myHandler(const char *event, const char *data)
{
Particle.publish("time incremented");
timepassed = timepassed + 1;
}
void spin(int R, int G, int B)
{
for(i=0;i<PIXEL_COUNT; i++)
{
strip.setPixelColor(i, R,G,B);
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!
You must login before you can post a comment. .