Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // constants won't change. They're used here to set pin numbers:
- const int Ls = 4; // the number of the lock pin
- const int Lock = 21; // the number of the Locked relay
- const int Us = 5; // the number of the unlock pin
- const int Lights = 17; // the number of the Lights relay
- // variables will change:
- int LsState = 0; // variable for reading the Lock status
- int UsState = 0; // variable for reading the Unlock status
- void setup() {
- pinMode(Lock, OUTPUT); // initialize Lock as an output:
- pinMode(Ls, INPUT); // initialize the Ls pushbutton as an input:
- pinMode(Lights, OUTPUT); // initialize the Lights pin as an output:
- pinMode(Us, INPUT); // initialize the Us pin as an input:
- }
- void loop() {
- // read the state of the Lock value:
- LsState = digitalRead(Ls); // check if the pushbutton is pressed. If it is, the LsState is HIGH:
- if (LsState == HIGH) { // turn Lock output on:
- digitalWrite(Lock, HIGH);
- digitalWrite(Lights, LOW);
- }
- // read the state of the Unlock value:
- UsState = digitalRead(Us); // check if the pushbutton is pressed. If it is, the UsState is HIGH:
- if (UsState == HIGH) { // turn Lights relay on:
- digitalWrite(Lights, HIGH);
- digitalWrite(Lock, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement