Advertisement
Guest User

Untitled

a guest
Dec 27th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. Const unsigned long pirDelay = 5 * 60 * 1000; // Set green LED delay for 5 minutes
  20. unsigned long lastOn_millis;
  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.   if (digitalRead(pirSensor1)== HIGH){
  42.     analogWrite(redPin,100);
  43.     analogWrite(greenPin,100);
  44.     analogWrite(bluePin,100);
  45.     //delay(5000);//for troubleshooting purposes    
  46.                                    
  47.     lastOn_millis = millis();
  48.    }
  49.  
  50.     if((millis() -  lastOn_millis > pirDelay) ||
  51.        (digitalRead(offButton) == HIGH) ){
  52.      
  53.        analogWrite(redPin,0); // Turn off all lights
  54.        analogWrite(greenPin,0);
  55.        analogWrite(bluePin,0);
  56.     }
  57.    delay(100); // optional
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement