-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlock.py
More file actions
26 lines (23 loc) · 1.02 KB
/
lock.py
File metadata and controls
26 lines (23 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#Import all neccessary features to code.
import RPi.GPIO as GPIO
from time import sleep
#If code is stopped while the solenoid is active it stays active
#This may produce a warning if the code is restarted and it finds the GPIO Pin, which it defines as non-active in next line, is still active
#from previous time the code was run. This line prevents that warning syntax popping up which if it did would stop the code running.
GPIO.setwarnings(True)
#This means we will refer to the GPIO pins
#by the number directly after the word GPIO. A good Pin Out Resource can be found here https://pinout.xyz/
GPIO.setmode(GPIO.BCM)
#This sets up the GPIO 2 pin as an output pin
GPIO.setup(2, GPIO.OUT)
while (True):
#This Turns Relay Off. Brings Voltage to Max GPIO can output ~3.3V
GPIO.output(2, 1)
print("DEBUG: lock should be locked")
#Wait 1 Seconds
sleep(1)
#Turns Relay On. Brings Voltage to Min GPIO can output ~0V.
GPIO.output(2, 0)
print("DEBUG: lock should be unlocked")
#Wait 1 Seconds
sleep(1)