Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_NeoPixel.h>
- #define PIN 6
- Adafruit_NeoPixel strip = Adafruit_NeoPixel(150, PIN, NEO_GRB + NEO_KHZ800);
- int calibrationTime = 10;
- unsigned long timer;
- unsigned long interval = 5000;
- unsigned long previousMillis = 0;
- int downUp = 0;
- int sawPir = 0;
- int pirPin = 11; //the digital pin connected to the PIR sensor's output
- int ledPin = 13;
- int ledPin2 = 10;
- void setup(){
- strip.begin();
- strip.show(); // Initialize all pixels to 'off'
- Serial.begin(9600);
- // led
- pinMode(ledPin, OUTPUT);
- pinMode(ledPin2, OUTPUT);
- // pir sensor
- pinMode(pirPin, INPUT);
- digitalWrite(pirPin, LOW);
- }
- //////////////////////////////LOOP
- void loop(){
- previousMillis = millis();
- if(digitalRead(pirPin) == HIGH && downUp != 2){ // top
- timer = millis();
- sawPir = 1;
- downUp = 2;
- // topdown();
- }
- //if the sensor is low or more than the given interval,
- //we assume that no more motion is going to happen
- if ( timer - previousMillis > interval){
- //makes sure this block of code is only executed again after
- //a new motion sequence has been detected
- if (downUp == 1){
- Serial.println("motion ended at downUp 1 (BOTTOM)"); //output
- }
- if (downUp == 2){
- Serial.println("motion ended at downUp 2 (TOP)"); //output
- colourWipeDown(strip.Color(0, 0, 0), 30); // Warm White
- }
- downUp = 0; // reset
- sawPir = 0; // reset
- Serial.print("motion ended at "); //output
- Serial.print((millis() - interval)/1000);
- Serial.println(" sec ");
- delay(1000);
- }
- } // end loop
- void topdown() {
- Serial.println("SAW YOU FROM TOP!"); // Helpful debug message
- colourWipeDown(strip.Color(50, 50, 30), 40); // Warm White
- for(int i=0; i<3; i++) { // Helpful debug indication flashes led on Arduino board twice
- digitalWrite(ledPin,HIGH);
- delay(200);
- digitalWrite(ledPin,LOW);
- delay(200);
- }
- }
- // Fill the dots one after the other with a color
- void colourWipeDown(uint32_t c, uint8_t wait) {
- for(uint16_t i=0; i<strip.numPixels(); i++) {
- strip.setPixelColor(i, c);
- strip.show();
- delay(wait);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement