-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMQ7.py
More file actions
44 lines (33 loc) · 800 Bytes
/
MQ7.py
File metadata and controls
44 lines (33 loc) · 800 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
import RPi.GPIO as GPIO
import time
import threading
import sys
DO = 15
LIGHT2 = 18
def definition():
GPIO.setmode(GPIO.BCM)
GPIO.setup(DO, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(LIGHT2, GPIO.OUT)
def action(pin):
print("Sensor detected action!")
GPIO.output(LIGHT2, 1)
time.sleep(1)
GPIO.output(LIGHT2, 0)
return
def fun2():
while True:
print("waiting for smoke")
GPIO.add_event_detect(DO, GPIO.RISING)
GPIO.add_event_callback(DO, action)
GPIO.remove_event_detect(DO)
def main():
try:
definition()
threads = []
t2 = threading.Thread(target=fun2)
threads.append(t2)
t2.start()
except KeyboardInterrupt:
GPIO.cleanup()
if __name__ == "__main__":
main()