2026-03-25 13:11:34 +01:00
|
|
|
"""
|
|
|
|
|
code adapté un une utilisation avec mcp3008 pour ldr
|
2026-03-25 13:00:59 +01:00
|
|
|
|
2026-03-25 13:11:34 +01:00
|
|
|
"""
|
2026-03-25 13:00:59 +01:00
|
|
|
|
|
|
|
|
|
2026-03-25 13:11:34 +01:00
|
|
|
import time
|
|
|
|
|
from gpiozero import LED, Button, PWMOutputDevice, AngularServo
|
|
|
|
|
from gpiozero import MCP3008
|
|
|
|
|
|
|
|
|
|
# LEDs
|
|
|
|
|
led_verte = LED(12)
|
|
|
|
|
led_verte_luminosite = LED(25)
|
|
|
|
|
led_rouge = LED(13)
|
|
|
|
|
led_bleue = LED(14)
|
|
|
|
|
led_rouge_gas = LED(10)
|
|
|
|
|
servo = AngularServo(32, min_angle=0, max_angle=180)
|
|
|
|
|
pir_sensor = Button(33)
|
|
|
|
|
gas_sensor = Button(34)
|
|
|
|
|
buzzer = PWMOutputDevice(11)
|
|
|
|
|
ldr_sensor = MCP3008(channel=0)
|
2026-03-25 13:00:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def activate_alarm():
|
|
|
|
|
for _ in range(3):
|
2026-03-25 13:11:34 +01:00
|
|
|
buzzer.value = 0.5
|
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
buzzer.value = 0
|
|
|
|
|
time.sleep(0.5)
|
2026-03-25 13:00:59 +01:00
|
|
|
|
|
|
|
|
def checkPin(guess):
|
|
|
|
|
if guess == secret_pin:
|
2026-03-25 13:11:34 +01:00
|
|
|
display_message("Code correct", guess)
|
2026-03-25 13:00:59 +01:00
|
|
|
led_verte.on()
|
2026-03-25 13:11:34 +01:00
|
|
|
servo.angle = 90
|
|
|
|
|
time.sleep(2)
|
|
|
|
|
servo.angle = 0
|
2026-03-25 13:00:59 +01:00
|
|
|
led_verte.off()
|
|
|
|
|
else:
|
2026-03-25 13:11:34 +01:00
|
|
|
display_message("Code incorrect", guess)
|
2026-03-25 13:00:59 +01:00
|
|
|
led_rouge.on()
|
|
|
|
|
activate_alarm()
|
2026-03-25 13:11:34 +01:00
|
|
|
time.sleep(2)
|
2026-03-25 13:00:59 +01:00
|
|
|
led_rouge.off()
|
|
|
|
|
|
|
|
|
|
def pir_detection():
|
|
|
|
|
while True:
|
2026-03-25 13:11:34 +01:00
|
|
|
if pir_sensor.is_pressed:
|
2026-03-25 13:00:59 +01:00
|
|
|
led_bleue.on()
|
2026-03-25 13:11:34 +01:00
|
|
|
time.sleep(3)
|
2026-03-25 13:00:59 +01:00
|
|
|
led_bleue.off()
|
2026-03-25 13:11:34 +01:00
|
|
|
time.sleep(0.1)
|
2026-03-25 13:00:59 +01:00
|
|
|
|
|
|
|
|
def luminosite_detection():
|
|
|
|
|
while True:
|
2026-03-25 13:11:34 +01:00
|
|
|
luminosite = ldr_sensor.value * 1023
|
|
|
|
|
print(luminosite)
|
2026-03-25 13:00:59 +01:00
|
|
|
if luminosite > 300:
|
|
|
|
|
led_verte_luminosite.on()
|
|
|
|
|
else:
|
|
|
|
|
led_verte_luminosite.off()
|
2026-03-25 13:11:34 +01:00
|
|
|
time.sleep(0.5)
|
2026-03-25 13:00:59 +01:00
|
|
|
|
2026-03-25 13:11:34 +01:00
|
|
|
import threading
|
|
|
|
|
threading.Thread(target=pir_detection, daemon=True).start()
|
|
|
|
|
threading.Thread(target=luminosite_detection, daemon=True).start()
|