Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Importing the Bluetooth Socket library
- import bluetooth
- # Importing the GPIO library to use the GPIO pins of Raspberry pi
- import RPi.GPIO as GPIO
- host = ""
- port = 1 # Raspberry Pi uses port 1 for Bluetooth Communication
- GPIO.setmode(GPIO.BOARD)
- #for i in range (29,38)
- # if i%2!=0
- GPIO.setup(29,GPIO.OUT)
- GPIO.setup(31,GPIO.OUT)
- GPIO.setup(33,GPIO.OUT)
- GPIO.setup(35,GPIO.OUT)
- GPIO.setup(37,GPIO.OUT)
- p1=GPIO.PWM(29,50)
- p2=GPIO.PWM(31,50)
- p3=GPIO.PWM(33,50)
- p4=GPIO.PWM(35,50)
- p5=GPIO.PWM(37,50)
- p1.start(7.5)
- p2.start(7.5)
- p3.start(7.5)
- p4.start(7.5)
- p5.start(7.5)
- # Creaitng Socket Bluetooth RFCOMM communication
- server = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
- print('Bluetooth Socket Created')
- try:
- server.bind((host, port))
- print("Bluetooth Binding Completed")
- except:
- print("Bluetooth Binding Failed")
- server.listen(1) # One connection at a time
- # Server accepts the clients request and assigns a mac address.
- client, address = server.accept()
- print("Connected To", address)
- print("Client:", client)
- try:
- while True:
- # Receivng the data.
- data = client.recv(1024) # 1024 is the buffer size.
- bufor=data.split(".")
- seekNumber=int(bufor[0])
- seekValue=int(bufor[1])
- print("Seekbar numer:",seekNumber)
- print("wartosc:",seekValue)
- duty = float(seekValue)/(180/(12.5-2.5)) + 2.5
- switch (seekNumber) {
- case 1: p2.ChangeDutyCycle(duty);
- break;
- case 2: p2.ChangeDutyCycle(duty);
- break;
- case 3: p3.ChangeDutyCycle(duty);
- break
- case 4: p4.ChangeDutyCycle(duty);
- break;
- case 5: p5.ChangeDutyCycle(duty);
- break;
- }
- time.sleep(2)
- except:
- # Making all the output pins LOW
- GPIO.cleanup()
- # Closing the client and server connection
- client.close()
- server.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement