-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMoisture.py
More file actions
52 lines (40 loc) · 979 Bytes
/
Copy pathMoisture.py
File metadata and controls
52 lines (40 loc) · 979 Bytes
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
import RPi.GPIO as GPIO
import time
import threading
import sys
HAM = 22
LIGHT3 = 27
def definition():
GPIO.setmode(GPIO.BCM)
GPIO.setup(HAM, GPIO.IN)
GPIO.setup(LIGHT3, GPIO.OUT)
def action2(pin):
print("sensor detect action2!")
GPIO.output(LIGHT3, 1)
time.sleep(1)
GPIO.output(LIGHT3, 0)
return
def fun3():
# while(True):
# print("waiting for moisture")
# GPIO.add_event_detect(HAM, GPIO.RISING)
# GPIO.add_event_callback(HAM, action2)
# GPIO.remove_event_detect(HAM)
while GPIO.input(HAM) == 0:
print("0")
while GPIO.input(HAM) == 1:
print("Water detected!!!")
GPIO.output(LIGHT3, 1)
time.sleep(1)
GPIO.output(LIGHT3, 0)
def main():
try:
definition()
threads = []
t3 = threading.Thread(target=fun3)
threads.append(t3)
t3.start()
except KeyboardInterrupt:
GPIO.cleanup()
if __name__ == "__main__":
main()