-
Notifications
You must be signed in to change notification settings - Fork 0
/
unlock_drawer.py
52 lines (36 loc) · 1.02 KB
/
unlock_drawer.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import subprocess
import database
import RPi.GPIO as GPIO
import time
from enum import Enum
class Shelf(Enum):
TOP = 16
MIDDLE = 20
BOTTOM = 21
def unlock_shelf(shelf):
print("Unlocking shelf")
# Set up GPIO using BCM numbering
GPIO.setmode(GPIO.BCM)
# Set up pin 26 as an output
GPIO.setup(shelf.value, GPIO.OUT)
# Turn on GPIO 26
GPIO.output(shelf.value, True)
# Wait for 20 seconds
time.sleep(20)
# Turn off GPIO 26
GPIO.output(shelf.value, False)
# Clean up GPIO
GPIO.cleanup()
def unlock_all():
GPIO.setmode(GPIO.BCM)
GPIO.setup(Shelf.TOP.value, GPIO.OUT)
GPIO.setup(Shelf.MIDDLE.value, GPIO.OUT)
GPIO.setup(Shelf.BOTTOM.value, GPIO.OUT)
GPIO.output(Shelf.TOP.value, True)
GPIO.output(Shelf.MIDDLE.value, True)
GPIO.output(Shelf.BOTTOM.value, True)
time.sleep(30) #300: 5 minutes
GPIO.output(Shelf.TOP.value, False)
GPIO.output(Shelf.MIDDLE.value, False)
GPIO.output(Shelf.BOTTOM.value, False)
GPIO.cleanup()