Advertisement
Guest User

Untitled

a guest
May 20th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. import bluetooth
  2. import RPi.GPIO as GPIO
  3. GPIO.setmode(GPIO.BCM)
  4.  
  5. led_pin = 21 #Pin 40.
  6.  
  7. GPIO.setup(led_pin, GPIO.OUT)
  8.  
  9. host = ""
  10. port = 1 #Comunicacion Bluetooth.
  11.  
  12. server = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
  13. print("Socket Creado")
  14.  
  15. try:
  16. server.bind((host, port))
  17. print("Bind Completado")
  18. except:
  19. print("Bind Fallido")
  20.  
  21. server.listen(1) #Una conexion a la vez.
  22. cliente, direccion = server.accept()
  23. print("Conectado a: ", direccion)
  24. print("Cliente: ", cliente)
  25.  
  26. try:
  27. while True:
  28. datos = cliente.recv(1024)
  29. print(datos)
  30. if datos == "A":
  31. GPIO.output(led_pin, True)
  32. elif datos == "B":
  33. GPIO.output(led_pin, Fals)e
  34. else:
  35. print("Solo A o B son estados validos.")
  36. except KeyboardInterrupt:
  37. GPIO.cleanup()
  38. server.close()
  39. cliente.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement