-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
60 lines (49 loc) · 1.4 KB
/
test.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
import socket
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(21, GPIO.IN)
class enum:
pushed = 0
unpushed = 1
def main():
btnDet = button()
btnDet.stateSender()
class button:
originTime = None
originState = None
isOrigin = True
originData = 1
alerted = False
def __init(self):
pass
def stateSender(self):
self.originState = enum.unpushed
while True:
inputIO = GPIO.input(21)
if(self.isOrigin and inputIO == self.originState):
self.originTime = time.time()
self.isOrigin = False
elif(inputIO == self.originState):
if(self.isTimeover(self.originTime)):
if(inputIO):
data = 1
else:
data = 2
if(self.originData != data):
self.alerted = False
self.originData = data
if(not self.alerted):
print(data)
self.alerted = True
else:
self.originState = inputIO
self.isOrigin = True
time.sleep(0.02)
def isTimeover(self, originTime):
if(time.time() - originTime > 3.0):
return True
else:
return False
if __name__ == "__main__":
main()