Advertisement
anoopmail

Fixed

Feb 26th, 2022
979
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // constants won't change. They're used here to set pin numbers:
  2. const int Ls = 4;     // the number of the lock pin
  3. const int Lock = 21;      // the number of the Locked relay
  4. const int Us = 5;     // the number of the unlock pin
  5. const int Lights = 17;      // the number of the Lights relay
  6.  
  7. // variables will change:
  8. int LsState = 0;         // variable for reading the Lock status
  9. int UsState = 0;         // variable for reading the Unlock status
  10.  
  11. void setup() {
  12.   pinMode(Lock, OUTPUT);  // initialize Lock as an output:
  13.   pinMode(Ls, INPUT); // initialize the Ls pushbutton as an input:
  14.   pinMode(Lights, OUTPUT); // initialize the Lights pin as an output:
  15.   pinMode(Us, INPUT);  // initialize the Us pin as an input:
  16. }
  17.  
  18. void loop() {
  19.   // read the state of the Lock value:
  20.   LsState = digitalRead(Ls);   // check if the pushbutton is pressed. If it is, the LsState is HIGH:
  21.   if (LsState == HIGH) {      // turn Lock output on:
  22.     digitalWrite(Lock, HIGH);
  23.     digitalWrite(Lights, LOW);
  24.     }
  25.    
  26.   // read the state of the Unlock value:
  27.   UsState = digitalRead(Us);   // check if the pushbutton is pressed. If it is, the UsState is HIGH:
  28.   if (UsState == HIGH) {      // turn Lights relay on:
  29.     digitalWrite(Lights, HIGH);
  30.     digitalWrite(Lock, LOW);    
  31.     }
  32.  
  33.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement