Facebook
From del ray 3, 8 Months ago, written in Plain Text.
This paste is a reply to Re: measure distance from del ray 2 - view diff
Embed
Download Paste or View Raw
Hits: 300
  1. import RPi.GPIO as GPIO
  2. import time
  3. import pygame
  4.  
  5. # ... (rest of the code remains the same)
  6.  
  7. try:
  8.     people_inside = 0  # Counter for people inside the room
  9.     entry_cooldown = False  # Flag to prevent rapid multiple entries
  10.     exit_cooldown = False  # Flag to prevent rapid multiple exits
  11.  
  12.     while True:
  13.         enter_distance = measure_distance(ENTER_TRIG_PIN, ENTER_ECHO_PIN, num_readings=5)
  14.         exit_distance = measure_distance(EXIT_TRIG_PIN, EXIT_ECHO_PIN, num_readings=5)
  15.  
  16.         # Detecting if someone is within 30 cm range for entry
  17.         if enter_distance < 30 and not entry_cooldown:
  18.             people_inside += 1
  19.             entry_cooldown = True
  20.             time.sleep(2)  # Entry cooldown period, adjust as needed
  21.  
  22.         # Detecting if someone is within 30 cm range for exit
  23.         if exit_distance < 30 and people_inside > 0 and not exit_cooldown:
  24.             people_inside -= 1
  25.             exit_cooldown = True
  26.             time.sleep(2)  # Exit cooldown period, adjust as needed
  27.  
  28.         if people_inside > 0:
  29.             play_audio()
  30.             control_led_strip(GPIO.HIGH)
  31.         else:
  32.             stop_audio()
  33.             control_led_strip(GPIO.LOW)
  34.  
  35.         if not (enter_distance < 30):
  36.             entry_cooldown = False
  37.  
  38.         if not (exit_distance < 30):
  39.             exit_cooldown = False
  40.  
  41. except KeyboardInterrupt:
  42.     GPIO.cleanup()
  43.     pygame.mixer.quit()
  44.  

Replies to Re: Re: measure distance rss

Title Name Language When
Re: Re: Re: measure distance del ray 4 text 8 Months ago.