價格:免費
更新日期:2018-08-18
檔案大小:1.4M
目前版本:1.0
版本需求:Android 4.2 以上版本
官方網站:mailto:tomcraftswales@gmail.com
p00kies HC-05 Bluetooth RC Joystick is a simple app designed to control Arduino Bluetooth projects, using the HC-05 Bluetooth Module using an analogue Joystick & 4 buttons on your phone or tablet.
The Data produced by the controls is sent out as a string of integers. Use the following sketch which shows how the data is recieved and sorted.
The Arduino Sketch
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include
SoftwareSerial mySerial(12, 11); // connect D12 to the TX on the HC-05 & D11 to RX on HC-05
const byte numChars = 16;
char receivedChars[numChars];
char recvChar;
char endMarker = '>';
boolean newData = false;
int joyX = 50; //Joystick X Axis
int joyY = 50; //Joystick X Axis
int btnA = 0; //Button A
int btnX = 0; //Button X
int btnB = 0; //Button B
int btnY = 0; //Button Y
void setup()
{
//HC-05 Serial Connection
mySerial.begin(9600);
//USB Serial Connection
Serial.begin(9600);
Serial.println("");
}
void loop()
{
recvData();
showData(); //Worth removing when doing your own project
//yourFunction(); //Place holder for your function //See Below
}
//Recieve incoming Data & store as a String
void recvData()
{
static byte nData = 0;
char badByte = ':';
char goodByte = ',';
char endMarker = '>';
char rc;
while (mySerial.available() > 0 && newData == false) {
rc = mySerial.read();
if (rc != endMarker)
{
if(rc == badByte) rc = goodByte;
receivedChars[nData] = rc;
nData++;
if (nData >= numChars)
{
nData = numChars - 1;
}
}
else
{
receivedChars[nData] = '\0'; // terminate the string
nData = 0;
parseData();
}
}
}
//Sort the Data & Store in Variables for use
void parseData() {
// split the data
char * strtokIndx; // this is used by strtok() as an index
strtokIndx = strtok(receivedChars,","); // Get 1st Chunk from Data string
joyX = atoi(strtokIndx); // Retrieve 1st value & convert to an integer
strtokIndx = strtok(NULL, ","); // Find Next Chunk
joyY = atoi(strtokIndx); // Retrieve 2nd value & convert to an integer
strtokIndx = strtok(NULL, ","); // Find Next Chunk
btnA = atoi(strtokIndx); // Retrieve 3rd value & convert to an integer
strtokIndx = strtok(NULL, ","); // Find Next Chunk
btnX = atoi(strtokIndx); // Retrieve 4th value & convert to an integer
strtokIndx = strtok(NULL,","); // Find Next Chunk
btnB = atoi(strtokIndx); // Retrieve 5th value & convert to an integer
strtokIndx = strtok(NULL, ","); // Find Next Chunk
btnY = atoi(strtokIndx); //Retrieve 6th value convert this part to an integer
newData = true;
}
//Show the incoming Data over local Serial(Debug)//
void showData() {
//Check you have newData to work with
if (newData == true)
{
//Here I'm stupidly reconcatinating the String for your viewing pleasure :D
String output = String(joyX) + "," + String(joyY) + "," + String(btnA) + "," + String(btnX) + "," + String(btnB) + "," + String(btnY);
//Shouting it out over the local serial assuming your testing the Arduino over usb (RX0, TX1)
Serial.println(output);
//And now Clearing the newData flag to start the process over
newData = false;
}
}
//Here's the place holder function with the nessacaries included
void yourFunction(){
//Check you have newData to work with
if (newData == true)
{
//Do your thang here!
//But remember to finish by clearing newData flag
newData = false;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////
Enjoy!
**Notes
***This App WILL Eat Your Battery