Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bluetooth
- import RPi.GPIO as GPIO
- GPIO.setmode(GPIO.BCM)
- led_pin = 21 #Pin 40.
- GPIO.setup(led_pin, GPIO.OUT)
- host = ""
- port = 1 #Comunicacion Bluetooth.
- server = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
- print("Socket Creado")
- try:
- server.bind((host, port))
- print("Bind Completado")
- except:
- print("Bind Fallido")
- server.listen(1) #Una conexion a la vez.
- cliente, direccion = server.accept()
- print("Conectado a: ", direccion)
- print("Cliente: ", cliente)
- try:
- while True:
- datos = cliente.recv(1024)
- print(datos)
- if datos == "A":
- GPIO.output(led_pin, True)
- elif datos == "B":
- GPIO.output(led_pin, Fals)e
- else:
- print("Solo A o B son estados validos.")
- except KeyboardInterrupt:
- GPIO.cleanup()
- server.close()
- cliente.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement