Advertisement
Guest User

Untitled

a guest
May 8th, 2015
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. const int PIRpin = 3;
  2. const int LDRpin = 0;
  3. const int LEDpin1 = 5;
  4. const int LEDpin2 = 6;
  5. const int LEDpin3 = 7;
  6. const int LEDpin4 = 8;
  7. const int LEDpin5 = 9;
  8. const int LEDpin6 = 10;
  9.  
  10.  
  11. void setup() {
  12.   pinMode(PIRpin, INPUT_PULLUP); // I'm assuming PIRpin is active low, it might not be.
  13.   pinMode(LEDpin1, OUTPUT); // Add more LED pins for each of them
  14.   pinMode(LEDpin2, OUTPUT); // Add more LED pins for each of them
  15.   pinMode(LEDpin3, OUTPUT); // Add more LED pins for each of them
  16.   pinMode(LEDpin4, OUTPUT); // Add more LED pins for each of them
  17.   pinMode(LEDpin5, OUTPUT); // Add more LED pins for each of them
  18.   pinMode(LEDpin6, OUTPUT); // Add more LED pins for each of them
  19.  
  20. }
  21.  
  22. void loop() {
  23.  
  24.   int LDR;
  25.   int LEDs;
  26.  
  27.   if(digitalRead(PIRpin) == LOW) // Is the PIR low?
  28.   {
  29.       LDR = analogRead(LDRpin);
  30.       LEDs = int(map(LDR,0,1023,6,1)); // Maps the 0-1023 reading from the LDR to between 6 (if the room is dark) and 1 (if the room is light) LEDs
  31.      
  32.       switch(LEDs)
  33.       {
  34.        case 6:
  35.          digitalWrite(LEDpin6,HIGH);
  36.        case 5:
  37.          digitalWrite(LEDpin5,HIGH);
  38.        case 4:
  39.          digitalWrite(LEDpin4,HIGH);
  40.        case 3:
  41.          digitalWrite(LEDpin3,HIGH);
  42.        case 2:
  43.          digitalWrite(LEDpin2,HIGH);
  44.        case 1:
  45.          digitalWrite(LEDpin1,HIGH);
  46.       }      
  47.        
  48.        
  49.   }
  50.   else
  51.   {
  52.          digitalWrite(LEDpin6,LOW);
  53.          digitalWrite(LEDpin5,LOW);
  54.          digitalWrite(LEDpin4,LOW);
  55.          digitalWrite(LEDpin3,LOW);
  56.          digitalWrite(LEDpin2,LOW);
  57.          digitalWrite(LEDpin1,LOW);
  58.   }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement