my parsed data is not showing but my serial read is
tx
/*
Example sketch for the PS4 Bluetooth library - developed by Kristian Lauszus
For more information visit my blog: http://blog.tkjelectronics.dk/ or
send me an e-mail: kristianl@tkjelectronics.com
*/
#include <PS4BT.h>
#include <usbhub.h>
// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#include <SPI.h>
#endif
USB Usb;
//USBHub Hub1(&Usb); // Some dongles have a hub inside
BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
/* You can create the instance of the PS4BT class in two ways */
// This will start an inquiry and then pair with the PS4 controller - you only have to do this once
// You will need to hold down the PS and Share button at the same time, the PS4 controller will then start to blink rapidly indicating that it is in paring mode
//PS4BT PS4(&Btd, PAIR);
// After that you can simply create the instance like so and then press the PS button on the device
PS4BT PS4(&Btd);
#include <Servo.h>
#include <SoftwareSerial.h>
SoftwareSerial xbee(5, 4); // TX, RX
int LYVALUE;
int LXVALUE;
int oldLYvalue;
int oldLXvalue;
int RYVALUE;
int RXVALUE;
int oldRYvalue;
int oldRXvalue;
int oldCvalue;
int oldDvalue;
int angleC = 96;
int angleD = 90;
int Forward;
int Backward;
int Movement;
int oldmove;
const byte numChars = 32;
char *msgForRx = "";
char *oldmsgForRx = "";
boolean Frwrd = false;
boolean Bkwrd = false;
bool printAngle, printTouch;
uint8_t oldL2Value, oldR2Value;
char receivedChars[numChars];
char tempChars[numChars];
char messageFromRx[numChars] = {0};
boolean newData = false;
boolean connection = false;
int tick = 0;
int timeout = 0;
int oldtimeout = 0;
void setup() {
Serial.begin(19200);
#if !defined(__MIPSEL__)
while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
#endif
if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start"));
while (1); // Halt
}
Serial.print(F("\r\nPS4 Bluetooth Library Started"));
xbee.begin(19200);
}
void loop() {
Usb.Task();
if (PS4.connected()) {
if (PS4.getAnalogHat(LeftHatX) || PS4.getAnalogHat(LeftHatY) || PS4.getAnalogHat(RightHatX) || PS4.getAnalogHat(RightHatY))
{
//Stick Values
LYVALUE = PS4.getAnalogHat(LeftHatY);
LYVALUE = map(LYVALUE, 0, 255, 130, 45);
LXVALUE = PS4.getAnalogHat(LeftHatX);
LXVALUE = map(LXVALUE, 0, 255, 39, 120);
RYVALUE = PS4.getAnalogHat(RightHatY);
RXVALUE = PS4.getAnalogHat(RightHatX);
}
//==================================================
if (PS4.getAnalogButton(R2) != oldR2Value && !Bkwrd) {// Only write value if it's different
oldR2Value = PS4.getAnalogButton(R2);
Forward = PS4.getAnalogButton(R2);
Forward = map(Forward, 0, 255, 88, 130);
Frwrd = true;
Movement = (Forward);
}
else {
Frwrd = false;
}
//==================================================
if (PS4.getAnalogButton(L2) != oldL2Value && !Frwrd) { // Only write value if it's different
oldL2Value = PS4.getAnalogButton(L2);
Backward = PS4.getAnalogButton(L2);
Backward = map(Backward, 0, 255, 87, 45);
Bkwrd = true;
Movement = (Backward);
}
else {
Bkwrd = false;
}
if (PS4.getButtonClick(PS)) {
Serial.print(F("\r\nPS"));
PS4.disconnect();
}
else {
if (PS4.getButtonClick(TRIANGLE)) {
msgForRx = "Triangle";
}
if (PS4.getButtonClick(CIRCLE)) {
msgForRx = "Circle";
}
if (PS4.getButtonClick(CROSS)) {
msgForRx = "Crosss";
// PS4.setLedFlash(10, 10); // Set it to blink rapidly
}
if (PS4.getButtonClick(SQUARE)) {
msgForRx = "Square";
//PS4.setLedFlash(0, 0); // Turn off blinking
}
if (PS4.getButtonClick(UP)) {
msgForRx = "Up";
//PS4.setLed(Red);
} if (PS4.getButtonClick(RIGHT)) {
msgForRx = "Right";
//PS4.setLed(Blue);
} if (PS4.getButtonClick(DOWN)) {
msgForRx = "Down";
//PS4.setLed(Yellow);
} if (PS4.getButtonClick(LEFT)) {
msgForRx = "Left";
//PS4.setLed(Green);
}
if (PS4.getButtonClick(L1))
msgForRx = "L1";
if (PS4.getButtonClick(L3))
msgForRx = "L3";
if (PS4.getButtonClick(R1))
msgForRx = "R1";
if (PS4.getButtonClick(R3))
msgForRx = "R3";
if (PS4.getButtonClick(SHARE))
msgForRx = "Share";
if (PS4.getButtonClick(OPTIONS)) {
msgForRx = "Options";
printAngle = !printAngle;
}
}
}
//pan
if (RXVALUE < 40 && angleC >= 0 && angleC < 180 ) {
angleC += 1;
}
if (RXVALUE > 160 && angleC > 0 && angleC <= 180) {
angleC -= 1;
}
//tilt
if (RYVALUE < 40 && angleD >= 0 && angleD < 180) {
angleD += 1;
}
if (RYVALUE > 160 && angleD > 0 && angleD <= 180) {
angleD -= 1;
}
delay(10);
recvWithStartEndMarkers();
if (newData == true) {
strcpy(tempChars, receivedChars);
// this temporary copy is necessary to protect the original data
// because strtok() replaces the commas with \0
parseData();
if (strcmp(messageFromRx, "connected") == 0) // test to see if the two strings are equal
{
connection = true;
timeout = 0;
}
delay(10);
newData = false;
}
//checkconnect();
if (Movement != oldmove || LXVALUE < (oldLXvalue - 1) || LXVALUE > (oldLXvalue + 1) || angleC != oldCvalue || angleD != oldDvalue || msgForRx != oldmsgForRx) {
Serial.print(F("<"));
Serial.print(msgForRx);
Serial.print(F(","));
Serial.print(Movement, DEC);
Serial.print(",");
Serial.print(LXVALUE, DEC);
Serial.print(F(","));
Serial.print(angleC, DEC);
Serial.print(F(","));
Serial.print(angleD, DEC);
Serial.println(F(">"));
xbee.print("<");
xbee.print(msgForRx);
xbee.print(",");
xbee.print(Movement, DEC);
xbee.print(",");
xbee.print(LXVALUE, DEC);
xbee.print(",");
xbee.print(angleC, DEC);
xbee.print(",");
xbee.print(angleD, DEC);
xbee.println(">");
oldLXvalue = LXVALUE;
oldLYvalue = LYVALUE;
oldRXvalue = RXVALUE;
oldRYvalue = RYVALUE;
oldCvalue = angleC;
oldDvalue = angleD;
}
msgForRx = "connected";
oldmsgForRx = msgForRx;
oldmove = Movement;
}
//=============
void recvWithStartEndMarkers() {
static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = '<';
char endMarker = '>';
char rc;
while (xbee.available() > 0 && newData == false) {
rc = xbee.read();
if (recvInProgress == true) {
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
newData = true;
}
}
else if (rc == startMarker) {
recvInProgress = true;
}
}
}
//============
void parseData() {
// split the data into its parts
char * strtokIndx; // this is used by strtok() as an index
strtokIndx = strtok(tempChars, ","); // get the first part - the string
strcpy(messageFromRx, strtokIndx); // copy it to messageFromPC
}
//============
void showParsedData() {
Serial.print(messageFromRx);
}
void checkconnect() {
if (!connection && tick == 0) {
Serial.println("Not connected");
tick = 1;
}
if (!connection || timeout >= 40) {
xbee.print("<");
xbee.print("connected");
xbee.print(",");
xbee.println(">");
}
delay(10);
if (connection && tick == 1) {
Serial.println("Connected!");
tick = 0;
}
delay(5);
if (connection) {
timeout += 1;
oldtimeout = timeout;
if (timeout >= 150) {
connection = false;
tick = 0;
}
}
}