Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. import bluetooth
  2. import RPi.GPIO as GPIO #calling for header file which helps in using GPIOs of PI
  3. LED=21
  4.  
  5. GPIO.setmode(GPIO.BCM) #programming the GPIO by BCM pin numbers. (like PIN40 as GPIO21)
  6. GPIO.setwarnings(False)
  7. GPIO.setup(LED,GPIO.OUT) #initialize GPIO21 (LED) as an output Pin
  8. GPIO.output(LED,0)
  9.  
  10. server_socket=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
  11.  
  12. port = 1
  13. server_socket.bind(("",port))
  14. server_socket.listen(1)
  15.  
  16. client_socket,address = server_socket.accept()
  17. print "Accepted connection from ",address
  18. while 1:
  19.  
  20. data = client_socket.recv(1024)
  21. print "Received: %s" % data
  22. if (data == "0"): #if '0' is sent from the Android App, turn OFF the LED
  23. print ("GPIO 21 LOW, LED OFF")
  24. GPIO.output(LED,0)
  25. if (data == "1"): #if '1' is sent from the Android App, turn OFF the LED
  26. print ("GPIO 21 HIGH, LED ON")
  27. GPIO.output(LED,1)
  28. if (data == "q"):
  29. print ("Quit")
  30. break
  31.  
  32. client_socket.close()
  33. server_socket.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement