Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- BEDROOM LIGHTS
- Primary lights, redced brightness green
- Secondary lights, warm white
- Primary controlled by PIR
- Secondary controlled by push button
- Push button off for both lights
- */
- int pirSensor1 = 7;
- int pirSensor2 = 8;
- int offButton = 3;
- boolean onButton = LOW;
- int redPin = 9;
- int greenPin = 10;
- int bluePin = 11;
- Const unsigned long pirDelay = 5 * 60 * 1000; // Set green LED delay for 5 minutes
- unsigned long lastOn_millis;
- void setup ()
- {
- pinMode(pirSensor1, INPUT);
- pinMode(pirSensor2, INPUT);
- pinMode(offButton, INPUT);
- pinMode(onButton, INPUT);
- pinMode(redPin, OUTPUT);
- pinMode(greenPin, OUTPUT);
- pinMode(bluePin, OUTPUT);
- analogWrite(redPin,0); // Turn off all lights
- analogWrite(greenPin,0);
- analogWrite(bluePin,0);
- }
- void loop (){
- if (digitalRead(pirSensor1)== HIGH){
- analogWrite(redPin,100);
- analogWrite(greenPin,100);
- analogWrite(bluePin,100);
- //delay(5000);//for troubleshooting purposes
- lastOn_millis = millis();
- }
- if((millis() - lastOn_millis > pirDelay) ||
- (digitalRead(offButton) == HIGH) ){
- analogWrite(redPin,0); // Turn off all lights
- analogWrite(greenPin,0);
- analogWrite(bluePin,0);
- }
- delay(100); // optional
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement