Advertisement
ironheartbj18

Untitled

Feb 21st, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. #include <Adafruit_NeoPixel.h>
  2.  
  3. #define PIN 6
  4.  
  5. Adafruit_NeoPixel strip = Adafruit_NeoPixel(150, PIN, NEO_GRB + NEO_KHZ800);
  6. int calibrationTime = 10;
  7. unsigned long timer;
  8. unsigned long interval = 5000;
  9. unsigned long previousMillis = 0;
  10.  
  11. int downUp = 0;
  12. int sawPir = 0;
  13.  
  14. int pirPin = 11; //the digital pin connected to the PIR sensor's output
  15. int ledPin = 13;
  16. int ledPin2 = 10;
  17.  
  18. void setup(){
  19. strip.begin();
  20. strip.show(); // Initialize all pixels to 'off'
  21. Serial.begin(9600);
  22.  
  23. // led
  24. pinMode(ledPin, OUTPUT);
  25. pinMode(ledPin2, OUTPUT);
  26.  
  27. // pir sensor
  28. pinMode(pirPin, INPUT);
  29. digitalWrite(pirPin, LOW);
  30. }
  31. //////////////////////////////LOOP
  32.  
  33. void loop(){
  34. previousMillis = millis();
  35. if(digitalRead(pirPin) == HIGH && downUp != 2){ // top
  36. timer = millis();
  37. sawPir = 1;
  38. downUp = 2;
  39. // topdown();
  40. }
  41.  
  42. //if the sensor is low or more than the given interval,
  43. //we assume that no more motion is going to happen
  44. if ( timer - previousMillis > interval){
  45. //makes sure this block of code is only executed again after
  46. //a new motion sequence has been detected
  47. if (downUp == 1){
  48. Serial.println("motion ended at downUp 1 (BOTTOM)"); //output
  49. }
  50. if (downUp == 2){
  51. Serial.println("motion ended at downUp 2 (TOP)"); //output
  52. colourWipeDown(strip.Color(0, 0, 0), 30); // Warm White
  53. }
  54. downUp = 0; // reset
  55. sawPir = 0; // reset
  56. Serial.print("motion ended at "); //output
  57. Serial.print((millis() - interval)/1000);
  58. Serial.println(" sec ");
  59. delay(1000);
  60. }
  61. } // end loop
  62.  
  63. void topdown() {
  64. Serial.println("SAW YOU FROM TOP!"); // Helpful debug message
  65. colourWipeDown(strip.Color(50, 50, 30), 40); // Warm White
  66. for(int i=0; i<3; i++) { // Helpful debug indication flashes led on Arduino board twice
  67. digitalWrite(ledPin,HIGH);
  68. delay(200);
  69. digitalWrite(ledPin,LOW);
  70. delay(200);
  71. }
  72. }
  73.  
  74. // Fill the dots one after the other with a color
  75. void colourWipeDown(uint32_t c, uint8_t wait) {
  76. for(uint16_t i=0; i<strip.numPixels(); i++) {
  77. strip.setPixelColor(i, c);
  78. strip.show();
  79. delay(wait);
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement