Necesito mezclar 2 scripts para que se me apague el monitor con un sensor de movimiento(PIR).
Publicado por René (3 intervenciones) el 09/10/2019 10:03:00
Código 1
Código 2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN, GPIO.PUD_DOWN)
estado_anterior = False
estado_actual = False
time.sleep(4)
while True:
time.sleep(1)
estado_previo = estado_actual
estado_actual = GPIO.input(4)
if estado_actual != estado_previo:
nuevo_estado = “ALARMA ON” if estado_actual else “ALARMA OFF”
print(nuevo_estado)
time.sleep(1)
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
53
54
55
56
# Import required Python libraries
import RPi.GPIO as GPIO
import time
# Use BCM GPIO references
# instead of physical pin numbers
GPIO.setmode(GPIO.BCM)
# Define GPIO to use on Pi
GPIO_PIR = 7
print “PIR Module Test (CTRL-C to exit)”
# Set pin as input
GPIO.setup(GPIO_PIR,GPIO.IN) # Echo
Current_State = 0
Previous_State = 0
try:
print “Waiting for PIR to settle …”
# Loop until PIR output is 0
while GPIO.input(GPIO_PIR)==1:
Current_State = 0
print ” Ready”
# Loop until users quits with CTRL-C
while True :
# Read PIR state
Current_State = GPIO.input(GPIO_PIR)
if Current_State==1 and Previous_State==0:
# PIR is triggered
import os
os.system(“xset dpms force on”)
# Record previous state
Previous_State=1
elif Current_State==0 and Previous_State==1:
# PIR has returned to ready state
import time
time.sleep(120)
import os
os.system(“xset dpms force off”)
Previous_State=0
# Wait for 10 milliseconds
# time.sleep(5)
except KeyboardInterrupt:
print ” Quit”
# Reset GPIO settings
GPIO.cleanup()
Valora esta pregunta
0