-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrinker.py
69 lines (52 loc) · 1.24 KB
/
drinker.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
import RPi.GPIO as GPIO
import time
from config import TOKEN
from py532lib.i2c import *
from py532lib.frame import *
from py532lib.constants import *
pn532 = Pn532_i2c()
pn532.SAMconfigure()
motorA1 = 4
motorA2 = 17
def stop():
GPIO.setup(4, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(17, GPIO.OUT, initial=GPIO.LOW)
def init():
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(17, GPIO.OUT, initial=GPIO.LOW)
def MotorControl(num):
if num != 0:
GPIO.output(motorA1, GPIO.HIGH)
GPIO.output(motorA2, GPIO.LOW)
elif num == 0:
GPIO.output(motorA1, GPIO.LOW)
GPIO.output(motorA2, GPIO.LOW)
def user_touch():
MotorControl(0)
data = pn532.read_mifare().get_data()
print("data: ",data)
sleep(0.5)
res = ""
for i in range(-7,0):
if i == -7 and int(data[i]) < 10:
res = "0"
res += str(hex(data[i]))[2:]
print("user code: ", res)
return res
def user_drink():
MotorControl(1)
sleep(1.5)
MotorControl(0)
def get_token():
return TOKEN
def clear():
init()
GPIO.cleanup()
if __name__ == "__main__":
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.OUT, initial=GPIO.LOW)
GPIO.setup(17, GPIO.OUT, initial=GPIO.LOW)
GPIO.output(motorA1, GPIO.LOW)
GPIO.output(motorA2, GPIO.LOW)
GPIO.cleanup()