Have created a simple remote control car app using Raspberry Pi Pico, H-Bridge (for the motors), and the Adafruit Bluefruit LE UART Friend.
Everything is connected and working fine for the most part. What I need help on is the following...
1. My phone is able to connect to the bluefruit and send it commands. I am unable to figure out how I can press and hold a direction and for the car to continue in that direction.
For example, in the app within the controller section there are 4 directions with numbers. If I were to press and hold the right direction how can I send to the pico that right has been pressed and know when right direction has been let go? Key up and key down events, does the Bluetooth handle that? Or is the app limited on what it can send? This is what I don't understand because I am new to bluetooth.
2. If key events are not possible there are times if I were to spam hitting a particular direction the messages will begin sending back strange messages and I am having difficulty flushing message buffer or clearing the message buffer. Any suggestions?
Here are some examples of the right-direction strange messages that I may get. uart.read will respond with the following messages...
- b'!B813!B804
!B813!B80b'
B813!B804b'!
813!B804b'!B
13!B804b'!B8
3!B804b'!B81
Within my while true I have the following code...
Code: Select all
command = str(uart.read(10))
if(command == "b'!B714!B705'"): # Left - direction has been pressed
print("Left was pressed!")
multi_dir_speed(speed, 1, speed, 0, 0.4)
elif(command == "b'!B813!B804'"): # Right - direction has been pressed
print("Right was pressed!")
multi_dir_speed(speed, 0, speed, -1, 0.4)
elif(command == "b'!B516!B507'"): # Up - direction has been pressed
print("Up was pressed!")
multi_dir_speed(speed, 1, speed, -1, 0.4)
elif(command == "b'!B615!B606'"): # Down - direction has been pressed
print("Down was pressed!")
multi_dir_speed(speed, -1, speed, 1, 0.4)
else:
# It's possible that there is left over items on the buffer
# print what is there then remove the remaining on the buffer
print(command)
uart.write(command)
command = uart.read(20)
uart.write(command)
# Obviously this does not work.
Any help would be greatly appreciated. Thanks!