From a9ebf09a84de1ba90c9f459b84b9989db2b0e1e3 Mon Sep 17 00:00:00 2001
From: guowenxue <guowenxue@gmail.com>
Date: Tue, 29 Jan 2019 23:24:22 +0800
Subject: [PATCH] Add infrared.py

---
 modules/python/infrared.py |   30 ++++++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/modules/python/infrared.py b/modules/python/infrared.py
new file mode 100644
index 0000000..6ab73b3
--- /dev/null
+++ b/modules/python/infrared.py
@@ -0,0 +1,30 @@
+import time
+import signal
+import RPi.GPIO as GPIO
+
+INFR_PIN=16
+
+def sig_proc(signum, frame):
+    print("Catch stop signal and program exit now...")
+    exit()
+
+signal.signal(signal.SIGINT, sig_proc)
+signal.signal(signal.SIGTERM, sig_proc)
+ 
+def init():
+    GPIO.setwarnings(False)
+    GPIO.setmode(GPIO.BOARD)
+    GPIO.setup(INFR_PIN, GPIO.IN)
+    pass
+ 
+def detct():
+    while True:
+        if GPIO.input(INFR_PIN) == True:
+            print time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))+"  Someone is closing!"
+        else:
+            print time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))+"  No one nearby!"
+        time.sleep(1) 
+init()
+detct()
+GPIO.cleanup()
+

--
Gitblit v1.9.1