Advertisement
sprinty200

BrickPi Python

Nov 19th, 2017
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.45 KB | None | 0 0
  1. from BrickPi import *
  2. BrickPiSetup()
  3. BrickPi.MotorEnable[PORT_A] = 1
  4. BrickPi.MotorEnable[PORT_B] = 1
  5. BrickPi.MotorEnable[PORT_C] = 1
  6. BrickPi.MotorEnable[PORT_D] = 1
  7.  
  8. while True:
  9.     c = raw_input ("Enter Direction")
  10.     if c == "8": #Foward
  11.         BrickPi.MotorSpeed[PORT_A] = -230
  12.         BrickPi.MotorSpeed[PORT_D] = -230
  13.         BrickPiUpdateValues()
  14.  
  15.         ot = time.time()
  16.         while(time.time() - ot < .7):
  17.             BrickPiUpdateValues()
  18.         time.sleep(.1)
  19.  
  20.     elif c == "2": #Reverse
  21.         BrickPi.MotorSpeed[PORT_A] = 230
  22.         BrickPi.MotorSpeed[PORT_D] = 230
  23.         BrickPiUpdateValues()
  24.  
  25.         ot = time.time()
  26.         while(time.time() - ot < .7):
  27.             BrickPiUpdateValues()
  28.         time.sleep(.1)
  29.  
  30.     elif c == "4": #Left
  31.         BrickPi.MotorSpeed[PORT_A] = 230
  32.         BrickPi.MotorSpeed[PORT_D] = -230
  33.         BrickPiUpdateValues()
  34.  
  35.         ot = time.time()
  36.         while(time.time() - ot < .5):
  37.             BrickPiUpdateValues()
  38.         time.sleep(.1)
  39.  
  40.     elif c == "6": #Right
  41.         BrickPi.MotorSpeed[PORT_A] = -230
  42.         BrickPi.MotorSpeed[PORT_D] = 230
  43.         BrickPiUpdateValues()
  44.  
  45.         ot = time.time()
  46.         while(time.time() - ot < .5):
  47.             BrickPiUpdateValues()
  48.         time.sleep(.1)
  49.  
  50.     elif c == "7": #Arm Up
  51.         BrickPi.MotorSpeed[PORT_B] = 100
  52.         BrickPiUpdateValues()
  53.  
  54.         ot = time.time()
  55.         while(time.time() - ot < .2):
  56.             BrickPiUpdateValues()
  57.         time.sleep(.1)
  58.  
  59.     elif c == "9": #Arm Down
  60.         BrickPi.MotorSpeed[PORT_B] = -100
  61.         BrickPiUpdateValues()
  62.  
  63.         ot = time.time()
  64.         while(time.time() - ot < .2):
  65.             BrickPiUpdateValues()
  66.         time.sleep(.1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement