Advertisement
silver2row

Trying Interrupts and Other Ideas...

Dec 5th, 2020
1,271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. from pysabertooth import Sabertooth
  2. from time import sleep
  3. import Adafruit_BBIO.GPIO as GPIO
  4. import MotorBridge
  5.  
  6. saber = Sabertooth('/dev/ttyS2', baudrate=9600, address=128, timeout=0.1)
  7.  
  8. LED  = "P8_28"
  9. Stop = "P8_29"
  10.  
  11. GPIO.setup(LED, GPIO.OUT)
  12. GPIO.setup(Stop, GPIO.IN)
  13. motor  = MotorBridge.MotorBridgeCape()
  14. MotorB = motor.StepperMotorBInit()
  15.  
  16. try:
  17.     while True:
  18.         if GPIO.input(LED):
  19.             GPIO.wait_for_edge(Stop, GPIO.RISING)
  20.             sleep(0.5)
  21.             saber.drive(1, 25)
  22.             sleep(5)
  23.             saber.drive(1, -25)
  24.             sleep(5)
  25.             GPIO.output(LED, GPIO.LOW)
  26.             sleep(2)
  27.             GPIO.output(LED, GPIO.HIGH)
  28.             sleep(4)
  29.         #saber.stop()
  30.         elif GPIO.wait_for_edge(Stop, GPIO.FALLING):
  31.             sleep(0.5)
  32.             saber.drive(1, 50)
  33.             sleep(5)
  34.             saber.drive(1, -50)
  35.             sleep(5)
  36.         elif GPIO.wait_for_edge(Stop, GPIO.RISING):
  37.             sleep(0.5)
  38.             MotorB
  39.             motor.StepperMotorBMove(0, 1000)
  40.         else:
  41.             MotorB
  42.             motor.StepperMotorBMove(2000, 1000)
  43.             sleep(2)
  44.             motor.StepperMotorBMove(-2000, 1000)
  45.             sleep(4)
  46.  
  47. except KeyboardInterrupt:
  48.     print("Hey!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement