SHARE
TWEET

Untitled

a guest Feb 14th, 2016 105 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import RPi.GPIO as GPIO
  2. import time
  3.  
  4. GPIO.setmode(GPIO.BCM)
  5. GPIO.setwarnings(False)
  6. coil_A_1_pin = 16 # pink
  7. coil_A_2_pin = 22 # orange
  8. coil_B_1_pin = 25 # blau
  9. coil_B_2_pin = 27 # gelb
  10.  
  11. coil_C_1_pin = 4  # pink
  12. coil_C_2_pin = 17 # orange
  13. coil_D_1_pin = 23 # blau
  14. coil_D_2_pin = 24 # gelb
  15.  
  16.  
  17. # anpassen, falls andere Sequenz
  18. StepCount = 4
  19. Seq = range(0, StepCount)
  20. Seq[0] = [1,0,0,0]
  21. Seq[1] = [0,0,1,0]
  22. Seq[2] = [0,1,0,0]
  23. Seq[3] = [0,0,0,1]
  24.  
  25. GPIO.setup(coil_A_1_pin, GPIO.OUT)
  26. GPIO.setup(coil_A_2_pin, GPIO.OUT)
  27. GPIO.setup(coil_B_1_pin, GPIO.OUT)
  28. GPIO.setup(coil_B_2_pin, GPIO.OUT)
  29.  
  30. zeita = 1
  31. zeitb = 0.5
  32.  
  33. def setStep(w1, w2, w3, w4):
  34.     GPIO.output(coil_A_1_pin, w1)
  35.     GPIO.output(coil_A_2_pin, w2)
  36.     GPIO.output(coil_B_1_pin, w3)
  37.     GPIO.output(coil_B_2_pin, w4)
  38.  
  39.    
  40. def forwardX(delay, steps):
  41.     for i in range(steps):
  42.         for j in range(StepCount):
  43.             setStep(Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3])
  44.             time.sleep(delay)
  45.  
  46. def backwardsX(delay, steps):
  47.     for i in range(steps):
  48.         for j in reversed(range(StepCount)):
  49.             setStep(Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3])
  50.             time.sleep(delay)
  51.  
  52. if __name__ == '__main__':
  53.     for x in range(1):
  54.         delay = 3
  55.                 steps = 55
  56.         forwardX(int(delay) / 1000.0, int(steps))
  57.         time.sleep(zeitb)
  58.        
  59.         steps = 55
  60.         backwardsX(int(delay) / 1000.0, int(steps))
  61.         time.sleep(zeita)
  62.  
  63. GPIO.setup(coil_C_1_pin, GPIO.OUT)
  64. GPIO.setup(coil_C_2_pin, GPIO.OUT)
  65. GPIO.setup(coil_D_1_pin, GPIO.OUT)
  66. GPIO.setup(coil_D_2_pin, GPIO.OUT)
  67.  
  68.  
  69. def setStep(w5, w6, w7, w8):
  70.     GPIO.output(coil_C_1_pin, w5)
  71.     GPIO.output(coil_C_2_pin, w6)
  72.     GPIO.output(coil_D_1_pin, w7)
  73.     GPIO.output(coil_D_2_pin, w8)
  74.  
  75.    
  76. def forwardY(delay, steps):
  77.     for i in range(steps):
  78.         for j in range(StepCount):
  79.             setStep(Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3])
  80.             time.sleep(delay)
  81.  
  82. def backwardsY(delay, steps):
  83.     for i in range(steps):
  84.         for j in reversed(range(StepCount)):
  85.             setStep(Seq[j][0], Seq[j][1], Seq[j][2], Seq[j][3])
  86.             time.sleep(delay)
  87.  
  88.            
  89. if __name__ == '__main__':
  90.     for x in range(1):
  91.         delay = 2
  92.         steps = 40
  93.             forwardY(int(delay) / 1000.0, int(steps))
  94.         time.sleep(zeitb)
  95.        
  96.         steps = 40
  97.         backwardsY(int(delay) / 1000.0, int(steps))
  98.         time.sleep(zeita)
  99.  
  100.  
  101.        
  102. GPIO.cleanup()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top