Skip to content

Instantly share code, notes, and snippets.

@wdelenclos
Created December 26, 2020 09:44
Show Gist options
  • Save wdelenclos/e8a95fbf3e15a06f46eabf3f395ab698 to your computer and use it in GitHub Desktop.
Save wdelenclos/e8a95fbf3e15a06f46eabf3f395ab698 to your computer and use it in GitHub Desktop.
# Needed modules will be imported and configured
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
# Declaration of the input pin which is connected with the sensor
GPIO_PIN = 4
GPIO.setup(GPIO_PIN, GPIO.IN, pull_up_down = GPIO.PUD_UP)
# Break between the results will be defined here (in seconds)
delayTime = 2.5
# main loop
try:
while True:
if GPIO.input(GPIO_PIN) == False:
print("Detected")
print('\a')
# Reset + Delay
time.sleep(delayTime)
# Scavenging work after the end of the program
except KeyboardInterrupt:
GPIO.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment