-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathavoid.py
More file actions
30 lines (23 loc) · 784 Bytes
/
Copy pathavoid.py
File metadata and controls
30 lines (23 loc) · 784 Bytes
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
# 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 = 24
GPIO.setup(GPIO_PIN, GPIO.IN, pull_up_down = GPIO.PUD_UP)
# Break between the results will be defined here (in seconds)
delayTime = 0.5
print "Sensor-Test [press ctrl+c to end]"
# main program loop
try:
while True:
if GPIO.input(GPIO_PIN) == True:
print "No obstacle"
else:
print "Obstacle detected"
print "---------------------------------------"
# Reset + Delay
time.sleep(delayTime)
# Scavenging work after the end of the program
except KeyboardInterrupt:
GPIO.cleanup()