-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRPIDoor.py
94 lines (42 loc) · 1.08 KB
/
RPIDoor.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import RPi.GPIO as GPIO
import time
controlPort = 18
GPIO.setmode(GPIO.BCM)
GPIO.setup(controlPort,GPIO.OUT)
cycleFreq = 50
pwm = GPIO.PWM(controlPort,cycleFreq)
# Duty cycle constants
left = 1.5
right = 2.5
middle = (right - left) / 2 + left
cycleMS = 1000 / cycleFreq
def startpwm(pos):
dcp = (pos * 100) / cycleMS
pwm.start(dcp)
time.sleep(.5)
# pwm.stop()
def move(pos):
startpwm(right)
dcp = (pos * 100) / cycleMS
pwm.ChangeDutyCycle(dcp)
time.sleep(.5)
def openDoor():
move(left)
time.sleep(5)
move(right)
pwm.stop()
#main program loop
startpwm(right)
while True:
file = open("idlist", "r")
readid = raw_input("scan id card")
while True:
line = file.readline()
if line.strip() == readid:
openDoor()
break
elif line == "":
print ("id does not match")
print (readid)
break
file.close()