Advertisement
Guest User

Untitled

a guest
May 21st, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.78 KB | None | 0 0
  1. # Importing the Bluetooth Socket library
  2. import bluetooth
  3. # Importing the GPIO library to use the GPIO pins of Raspberry pi
  4. import RPi.GPIO as GPIO
  5.  
  6. host = ""
  7. port = 1    # Raspberry Pi uses port 1 for Bluetooth Communication
  8. GPIO.setmode(GPIO.BOARD)
  9. #for i in range (29,38)
  10. #   if i%2!=0
  11. GPIO.setup(29,GPIO.OUT)
  12. GPIO.setup(31,GPIO.OUT)
  13. GPIO.setup(33,GPIO.OUT)
  14. GPIO.setup(35,GPIO.OUT)
  15. GPIO.setup(37,GPIO.OUT)
  16.  
  17. p1=GPIO.PWM(29,50)
  18. p2=GPIO.PWM(31,50)
  19. p3=GPIO.PWM(33,50)
  20. p4=GPIO.PWM(35,50)
  21. p5=GPIO.PWM(37,50)
  22.  
  23. p1.start(7.5)
  24. p2.start(7.5)
  25. p3.start(7.5)
  26. p4.start(7.5)
  27. p5.start(7.5)
  28.  
  29. # Creaitng Socket Bluetooth RFCOMM communication
  30. server = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
  31. print('Bluetooth Socket Created')
  32.  
  33. try:
  34.     server.bind((host, port))
  35.     print("Bluetooth Binding Completed")
  36. except:
  37.     print("Bluetooth Binding Failed")
  38.  
  39. server.listen(1) # One connection at a time
  40. # Server accepts the clients request and assigns a mac address.
  41. client, address = server.accept()
  42. print("Connected To", address)
  43. print("Client:", client)
  44.  
  45. try:
  46.     while True:
  47.         # Receivng the data.
  48.         data = client.recv(1024) # 1024 is the buffer size.
  49.         bufor=data.split(".")
  50.         seekNumber=int(bufor[0])
  51.         seekValue=int(bufor[1])
  52.         print("Seekbar numer:",seekNumber)
  53.         print("wartosc:",seekValue)
  54.         duty = float(seekValue)/(180/(12.5-2.5)) + 2.5
  55.         switch (seekNumber) {
  56.             case 1: p2.ChangeDutyCycle(duty);
  57.                     break; 
  58.             case 2: p2.ChangeDutyCycle(duty);
  59.                     break;
  60.             case 3: p3.ChangeDutyCycle(duty);
  61.                     break
  62.             case 4: p4.ChangeDutyCycle(duty);
  63.                     break;
  64.             case 5: p5.ChangeDutyCycle(duty);
  65.                     break;
  66.             }
  67.                    
  68.         time.sleep(2)
  69.  
  70. except:
  71.     # Making all the output pins LOW
  72.     GPIO.cleanup()
  73.     # Closing the client and server connection
  74.     client.close()
  75.     server.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement