-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpool_filler_with_print.py
executable file
·70 lines (52 loc) · 1.42 KB
/
pool_filler_with_print.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
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
from datetime import datetime
import smtplib
from collections import Counter
def most_common(lst):
data = Counter(lst)
return max(lst, key=data.get)
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def filler(bucket, timer):
forth = GPIO.input(18)
if most_common(bucket) == 0:
if timer == 0:
pass
elif timer == 1:
timer = 0
GPIO.cleanup()
time.sleep(.25)
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP)
elif most_common(bucket) == 1:
if timer == 0:
timer = 1
GPIO.setup(17, GPIO.OUT)
GPIO.output(17, 0)
elif timer == 1:
pass
if forth == False:
bucket.append(0)
if len(bucket) == 10:
del bucket[0]
return 0, timer, bucket
elif forth == True:
bucket.append(1)
if len(bucket) == 10:
del bucket[0]
return 1, timer, bucket
t = 0
bucket = [0]
try:
while True:
state, t, bucket = filler(bucket, t)
print('State: {}'.format(state))
print('t: {}'.format(t))
print('Bucket: {}'.format(bucket))
time.sleep(2)
except KeyboardInterrupt:
print('\ncleaning GPIO')
GPIO.cleanup()
print('OK')