SHARE
TWEET

Untitled

a guest Jan 23rd, 2020 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import RPi.GPIO as GPIO          
  2. from time import sleep
  3.  
  4. in1 = 24
  5. in2 = 23
  6. en = 25
  7. temp1=1
  8.  
  9. GPIO.setmode(GPIO.BCM)
  10. GPIO.setup(in1,GPIO.OUT)
  11. GPIO.setup(in2,GPIO.OUT)
  12. GPIO.setup(en,GPIO.OUT)
  13. GPIO.output(in1,GPIO.LOW)
  14. GPIO.output(in2,GPIO.LOW)
  15. p=GPIO.PWM(en,1000)
  16.  
  17. p.start(25)
  18. print("\n")
  19. print("The default speed & direction of motor is LOW & Forward.....")
  20. print("r-run s-stop f-forward b-backward l-low m-medium h-high e-exit")
  21. print("\n")    
  22.  
  23. while(1):
  24.  
  25.     x=raw_input()
  26.    
  27.     if x=='r':
  28.         print("run")
  29.         if(temp1==1):
  30.          GPIO.output(in1,GPIO.HIGH)
  31.          GPIO.output(in2,GPIO.LOW)
  32.          print("forward")
  33.          x='z'
  34.         else:
  35.          GPIO.output(in1,GPIO.LOW)
  36.          GPIO.output(in2,GPIO.HIGH)
  37.          print("backward")
  38.          x='z'
  39.  
  40.  
  41.     elif x=='s':
  42.         print("stop")
  43.         GPIO.output(in1,GPIO.LOW)
  44.         GPIO.output(in2,GPIO.LOW)
  45.         x='z'
  46.  
  47.     elif x=='f':
  48.         print("forward")
  49.         GPIO.output(in1,GPIO.HIGH)
  50.         GPIO.output(in2,GPIO.LOW)
  51.         temp1=1
  52.         x='z'
  53.  
  54.     elif x=='b':
  55.         print("backward")
  56.         GPIO.output(in1,GPIO.LOW)
  57.         GPIO.output(in2,GPIO.HIGH)
  58.         temp1=0
  59.         x='z'
  60.  
  61.     elif x=='l':
  62.         print("low")
  63.         p.ChangeDutyCycle(25)
  64.         x='z'
  65.  
  66.     elif x=='m':
  67.         print("medium")
  68.         p.ChangeDutyCycle(50)
  69.         x='z'
  70.  
  71.     elif x=='h':
  72.         print("high")
  73.         p.ChangeDutyCycle(75)
  74.         x='z'
  75.      
  76.    
  77.     elif x=='e':
  78.         GPIO.cleanup()
  79.         print("GPIO Clean up")
  80.         break
  81.    
  82.     else:
  83.         print("<<<  wrong data  >>>")
  84.         print("please enter the defined data to continue.....")
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
Top