Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. import RPi.GPIO as GPIO
  2. import time
  3.  
  4. GPIO.setmode(GPIO.BCM)
  5. GPIO.setwarnings(False)
  6. coil_A_1_pin = 4 # pink
  7. coil_A_2_pin = 17 # orange
  8. coil_B_1_pin = 23 # blue
  9. coil_B_2_pin = 24 # yellow
  10.  
  11. # adjust if different
  12. StepCount = 8
  13. Seq = range(0, StepCount)
  14. Seq[0] = [0,1,0,0]
  15. Seq[1] = [0,1,0,1]
  16. Seq[2] = [0,0,0,1]
  17. Seq[3] = [1,0,0,1]
  18. Seq[4] = [1,0,0,0]
  19. Seq[5] = [1,0,1,0]
  20. Seq[6] = [0,0,1,0]
  21. Seq[7] = [0,1,1,0]
  22.  
  23. GPIO.setup(enable_pin, GPIO.OUT)
  24. GPIO.setup(coil_A_1_pin, GPIO.OUT)
  25. GPIO.setup(coil_A_2_pin, GPIO.OUT)
  26. GPIO.setup(coil_B_1_pin, GPIO.OUT)
  27. GPIO.setup(coil_B_2_pin, GPIO.OUT)
  28.  
  29. GPIO.output(enable_pin, 1)
  30.  
  31. def setStep(w1, w2, w3, w4):
  32. GPIO.output(coil_A_1_pin, w1)
  33. GPIO.output(coil_A_2_pin, w2)
  34. GPIO.output(coil_B_1_pin, w3)
  35. GPIO.output(coil_B_2_pin, w4)
  36.  
  37. def forward(delay, steps):
  38. for i in range(steps):
  39. for j in range(StepCount):
  40. setStep(Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3])
  41. time.sleep(delay)
  42.  
  43. def backwards(delay, steps):
  44. for i in range(steps):
  45. for j in reversed(range(StepCount)):
  46. setStep(Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3])
  47. time.sleep(delay)
  48.  
  49. if __name__ == '__main__':
  50. while True:
  51. delay = raw_input("Time Delay (ms)?")
  52. steps = raw_input("How many steps forward? ")
  53. forward(int(delay) / 1000.0, int(steps))
  54. steps = raw_input("How many steps backwards? ")
  55. backwards(int(delay) / 1000.0, int(steps))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement