-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
38 lines (27 loc) · 855 Bytes
/
main.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
from machine import Pin, TouchPad
from time import sleep
def start_pump(duration=3):
RELAY(0) # on
sleep(duration)
RELAY(1) # off
if __name__ == "__main__":
# setup
RELAY = Pin(15, Pin.OUT)
# turn RELAY off at startup
RELAY(1)
WATERING_TIME = '2:51'
surface = TouchPad(Pin(12))
threshold = []
# scan surface to calibrate
for x in range(12):
threshold.append(surface.read())
sleep(0.2)
threshold = sum(threshold)/len(threshold)
while True:
capacitance = surface.read()
capacitance_ratio = capacitance / threshold
if 0.40 < capacitance_ratio < 0.90:
print('Capacitance: {0}, Diff: {1}, Ratio: {2}'.format(
capacitance, threshold - capacitance, capacitance_ratio))
start_pump()
sleep(0.2)