I am working on a remote controlled vehicle based project. I am using a PS3 bluetooth controller for this purpose & am facing the problem described below. Any help would be appreciated.
Basically, the motors are connected to the MEGA which is connected to a USB Host Shield. A bluetooth dongle is connected to the shield. This dongle & shield enable MEGA to communicate with PS3 wirelessly. I am using the USB Host 2.0 library available for Arduino on GitHub.
if ( PS3.PS3Connected || PS3.PS3NavigationConnected )
if ( PS3.getAnalogButton(UP) )
if ( PS3.getAnalogButton(DOWN) )
if ( PS3.getAnalogButton(LEFT) )
if ( PS3.getAnalogButton(RIGHT) )
This is the code inside loop(). If anyone is wondering why getAnalogButton is used instead of getButtonClick, the reason is to enable the vehicle to move ahead as long as UP is pressed & so on. This was an improvisation on our part.
As can be seen, the function prints UP, DOWN, LEFT or RIGHT as long as they are pressed continuously. The problem is that it works perfect for a while. But then, it enters an infinite loop & stops taking input from the PS3.
// At this point it hangs without printing any further inputs.
Can someone help tackle this problem? It is essential for us to move the vehicle as long as the buttons are pressed & stop when button is released. Unfortunately, there is no feature to detect PRESSED or RELEASED state for PS3. Any help would mean a lot.
Also, we initially thought that the hang was because of overflowing the serial input. So, we removed all Serial messages & tested with LEDs. But, the same problem is still faced.