Advertisement
cbonzo69

BedroomLts_3

Dec 27th, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.39 KB | None | 0 0
  1. /*
  2. BEDROOM LIGHTS  
  3. Primary lights, redced brightness green
  4. Secondary lights, warm white
  5. Primary controlled by PIR
  6. Secondary controlled by push button
  7. Push button off for both lights
  8. */
  9.  
  10. int  pirSensor1 = 7;
  11. int  pirSensor2 = 8;
  12. int  offButton = 3;
  13. boolean onButton = LOW;
  14.  
  15. int redPin = 9;
  16. int greenPin = 10;
  17. int bluePin = 11;
  18.  
  19. long priDel = 15000; // Set green LED delay for 5 minutes
  20. long timer = 0;
  21.  
  22. void setup ()
  23. {
  24.  
  25.   pinMode(pirSensor1, INPUT);
  26.   pinMode(pirSensor2, INPUT);
  27.   pinMode(offButton, INPUT);
  28.   pinMode(onButton, INPUT);
  29.   pinMode(redPin, OUTPUT);
  30.   pinMode(greenPin, OUTPUT);
  31.   pinMode(bluePin, OUTPUT);
  32.  
  33.   analogWrite(redPin,0); // Turn off all lights
  34.   analogWrite(greenPin,0);
  35.   analogWrite(bluePin,0);
  36.  
  37. }
  38.  
  39.  
  40. void loop ()
  41. {
  42.   if (digitalRead(pirSensor1)== HIGH)// Read PIR sensor
  43.   {
  44.     analogWrite(redPin,100);//Turn lights on
  45.     analogWrite(greenPin,100);
  46.     analogWrite(bluePin,100);
  47.     //delay(5000);
  48.        
  49.     timer = millis() + priDel;//Set delay
  50.    
  51.   }
  52.     if(millis() < timer)//Run timer
  53.      
  54.    {
  55.       if (digitalRead(offButton) == HIGH)//Read manual off button
  56.       {
  57.         ltsOut();    
  58.       }
  59.     }
  60.     //delay(5000);
  61.    timer = 0;//Execute at completion of timer
  62.     ltsOut();
  63. }
  64.  
  65. void ltsOut()
  66. {
  67.   analogWrite(redPin,0); // Turn off all lights
  68.   analogWrite(greenPin,0);
  69.   analogWrite(bluePin,0);
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement