Created
December 29, 2018 11:38
-
-
Save EspaceRaspberryFrancais/b0f66776101a3c8cbabdac761801bfad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RPi.GPIO as GPIO | |
import time | |
GPIO.setmode(GPIO.BCM) | |
print "+-----------------------------------------------------------+" | |
print "| Mesure de distance par le capteur ultrasonore HC-SR04 |" | |
print "+-----------------------------------------------------------+" | |
Trig = 23 # Entree Trig du HC-SR04 branchee au GPIO 23 | |
Echo = 24 # Sortie Echo du HC-SR04 branchee au GPIO 24 | |
GPIO.setup(Trig,GPIO.OUT) | |
GPIO.setup(Echo,GPIO.IN) | |
GPIO.output(Trig, False) | |
repet = input("Entrez un nombre de repetitions de mesure : ") | |
for x in range(repet): # On prend la mesure "repet" fois | |
time.sleep(1) # On la prend toute les 1 seconde | |
GPIO.output(Trig, True) | |
time.sleep(0.00001) | |
GPIO.output(Trig, False) | |
while GPIO.input(Echo)==0: ## Emission de l'ultrason | |
debutImpulsion = time.time() | |
while GPIO.input(Echo)==1: ## Retour de l'Echo | |
finImpulsion = time.time() | |
distance = round((finImpulsion - debutImpulsion) * 340 * 100 / 2, 1) ## Vitesse du son = 340 m/s | |
print "La distance est de : ",distance," cm" | |
GPIO.cleanup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment