Page 124 - TCS ICT Book 8
P. 124
The City School 2021-2022
#activating the on-board bluetooth
server_sock=BluetoothSocket(RFCOMM)
port = 1
server_sock.bind(("",port))
server_sock.listen(1)
port=server_sock.getsockname()[1]
GPIO.output(16,True)
uuid ="94f39d29-7d6d-437d-973b-fba39e49d4ee"
advertise_service(server_sock,"SampleServe",service_id=uuid,
service_classes=[uuid,SERIAL_PORT_CLASS],
profiles=[SERIAL_PORT_PROFILE],)
client_sock,client_info=server_sock.accept()
print("Accept connection",client_info)
#setting conditions
while True:
data=client_sock.recv(1024)
print(“Receive[ %s]” % data)
if (data == ”quit”):
print(“quit”)
GPIO.cleanup()
break
#forward functionality
elif (data == ”F”):
GPIO.output(MotorL1,True)
GPIO.output(MotorL2,False)
GPIO.output(MotorR1,True)
GPIO.output(MotorR2,False)
#backward functionality
elif (data == ”D”):
GPIO.output(MotorL1,False)
GPIO.output(MotorL2,True)
GPIO.output(MotorR1,False)
GPIO.output(MotorR2,True)
124

