Created
December 29, 2018 11:42
-
-
Save EspaceRaspberryFrancais/cbb8cdad17e33f8143d0496f0020e56f 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) | |
GPIO.setup(17, GPIO.OUT) | |
GPIO.setwarnings(False) | |
ajoutAngle = 5 | |
print("\n+----------/ ServoMoteur Controlleur /----------+") | |
print("| |") | |
print("| Le Servo doit etre branche au pin 11 / GPIO 17 |") | |
print("| |") | |
print("+------------------------------------------------+\n") | |
print("Comment controler le Servo ?") | |
choix = int(input("1. Choisir un angle\n2. Faire tourner de 0 a 180\n")) | |
if (choix == 2) : | |
nbrTour = int(input("Entrez le nombre d'aller-retour que fera le Servo :\n")) | |
pwm=GPIO.PWM(17,100) | |
pwm.start(5) | |
angle1 = 0 | |
duty1 = float(angle1)/10 + ajoutAngle | |
angle2=180 | |
duty2= float(angle2)/10 + ajoutAngle | |
i = 0 | |
while i <= nbrTour: | |
pwm.ChangeDutyCycle(duty1) | |
time.sleep(0.8) | |
pwm.ChangeDutyCycle(duty2) | |
time.sleep(0.8) | |
i = i+1 | |
GPIO.cleanup() | |
if (choix == 1) : | |
angle = float(input("Entrez l'angle souhaite :\n")) | |
duree = int(input("Entrez la duree durant laquelle le Servo devra tenir sa position : ( en secondes )\n")) | |
pwm=GPIO.PWM(17,100) | |
pwm.start(5) | |
angleChoisi = angle/10 + ajoutAngle | |
pwm.ChangeDutyCycle(angleChoisi) | |
time.sleep(duree) | |
GPIO.cleanup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment