Advertisement
cbonzo69

Bedroom lights

Dec 26th, 2014
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.45 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.  
  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)
  43.   {
  44.     analogWrite(redPin,100);
  45.     analogWrite(greenPin,100);
  46.     analogWrite(bluePin,100);
  47.     delay(5000);//for troubleshooting purposes    
  48.                                    
  49.     long timer = millis() + priDel;
  50.     if(millis() < timer)//This is not working to read the offButton
  51.      
  52.    {
  53.       if (digitalRead(offButton) == HIGH)
  54.       {
  55.      
  56.        analogWrite(redPin,0); // Turn off all lights
  57.        analogWrite(greenPin,0);
  58.        analogWrite(bluePin,0);
  59.      
  60.       }
  61.     }
  62.    delay(5000);
  63.    timer = 0;    analogWrite(redPin,0); // Turn off all lights
  64.     analogWrite(greenPin,0);
  65.     analogWrite(bluePin,0);
  66.   }  
  67.    
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement