Files
CARIA-AUTOMOTIVE/WebControl/tests/infrared_obstacle_module.py
ccunatbrule 9ae7f229e7 CARIA.2.0
Repo initial CARIA :
MAJ Interface Bootle amélioré
- Optimisation de la structure
- amélioration des fonctionnalités
- debug
. . .
2024-05-28 15:47:08 +02:00

27 lines
574 B
Python

#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import RPi.GPIO as GPIO
import time
ObstaclePin = 16
def setup():
GPIO.setmode(GPIO.BCM)
GPIO.setup(ObstaclePin, GPIO.IN)
def loop():
while True:
if GPIO.input(ObstaclePin) == GPIO.LOW:
print("Obstacle détecté")
else:
print("Aucun obstacle détecté")
time.sleep(0.5) # Attendre un peu entre les lectures pour éviter les faux positifs
if __name__ == '__main__':
setup()
try:
loop()
except KeyboardInterrupt:
GPIO.cleanup()