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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| #-*-coding:Latin-1 -*
from BrickPi import *
import time
def avancer():
BrickPi.MotorSpeed[PORT_A] = 200
BrickPi.MotorSpeed[PORT_B] = 200
def gauche():
BrickPi.MotorSpeed[PORT_A] = -100
BrickPi.MotorSpeed[PORT_B] = 100
def droite():
BrickPi.MotorSpeed[PORT_A] = 100
BrickPi.MotorSpeed[PORT_B] = -100
def reculer():
BrickPi.MotorSpeed[PORT_A] = -200
BrickPi.MotorSpeed[PORT_B] = -200
def stop():
BrickPi.MotorSpeed[PORT_A] = 0
BrickPi.MotorSpeed[PORT_B] = 0
BrickPiSetup()
BrickPi.SensorType[PORT_1] = TYPE_SENSOR_TOUCH
BrickPi.MotorEnable[PORT_A] = 1
BrickPi.MotorEnable[PORT_B] = 1
BrickPiSetupSensors()
BrickPi.Timeout=1000
while True:
valeur= BrickPiUpdateValues()
print("Z:Avancer, S:Reculer, Q:Tourner à gauche, D:Tourner à droite, A:Stop")
if not valeur:
commande=str(raw_input())
if commande=='z':
avancer()
print("avance")
elif commande=='q':
gauche()
print("tourne à gauche")
elif commande =='d':
droite()
print("tourne à droite")
elif commande=='s':
reculer()
print("recule")
#Créer une condition pour qu'on arrête de reculer lorsque le capteur sensoriel est en contact.
elif commande=='a':
stop()
print("stop")
time.sleep(0.01) |
Partager