// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>
// This #include statement was automatically added by the Particle IDE.
#include <SharpIR.h>
#include <math.h>
#define PIXEL_PIN D2
#define PIXEL_COUNT 20
#define PIXEL_TYPE WS2812B
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
//int led = D2
int IR = A0;
int button = D3;
float value = 0.0;
bool seeingPerson = false;
long lastCount = millis();
int passCount = 0;
void setup() {
//pinMode(led, OUTPUT);
pinMode(IR, INPUT);
pinMode(button, INPUT_PULLDOWN);
Serial.begin(9600);
strip.begin();
strip.show();
}
void loop() {
float volts = float(analogRead(IR))*0.0048828125;
int distance = 13 * pow(volts, -1);
value = (value * 0.7) + (distance * 0.3);
if (digitalRead(D3)) {
passCount = 0;
for(int i = 0; i < strip.numPixels(); i++){
strip.setPixelColor(i, 0, 0, 0);
strip.show();
delay(100);
}
}
if (value <= 2){
if(!seeingPerson && (millis() - lastCount > 2000)){
lastCount = millis();
if (passCount < 40) {
passCount++;
if((passCount == 6) || (passCount == 16) || (passCount == 26) || (passCount == 36)){
passCount += 2;
}
}
Serial.println(passCount);
for(int i = 0; ((i < (passCount / 2)) && (i < PIXEL_COUNT)); i++){
int fade = min(passCount * 6, 255);
strip.setPixelColor(i, fade, 255- fade, 0);
}
strip.show();
seeingPerson = true;
}
//Serial.println(int(value));
}
else{
seeingPerson = false;
}
}
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. .