You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
729 B
40 lines
729 B
#人体接近传感器示例 |
|
|
|
|
|
import RPi.GPIO as GPIO |
|
import time |
|
import sqlite_connector |
|
|
|
# 初始化 |
|
def init(): |
|
# 设置不显示警告 |
|
GPIO.setwarnings(False) |
|
# 设置读取面板针脚模式 |
|
GPIO.setmode(GPIO.BOARD) |
|
# 设置读取针脚标号 |
|
GPIO.setup(11, GPIO.IN) |
|
pass |
|
|
|
|
|
def detct(): |
|
while True: |
|
curtime = time.strftime('%Y-%m-%d-%H-%M-%S', time.localtime(time.time())) |
|
# 当高电平信号输入时报警 |
|
if GPIO.input(11) == True: |
|
alart(curtime) |
|
print(GPIO.input(11)) |
|
else: |
|
continue |
|
time.sleep(3) |
|
|
|
|
|
def alart(curtime): |
|
print(curtime + " Someone is coming!") |
|
|
|
|
|
time.sleep(2) |
|
init() |
|
detct() |
|
GPIO.cleanup() |
|
|
|
|
|
|