Thanks for your help. You were correct, I did not # include <PS4Parser.h>. Now I can get the battery level reading displayed on the serial monitor.
the code looks like this:
// Build your own robot arm - remote control
/*
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 <PS4USB.h>
#include <usbhub.h>
#include <PS4Parser.h>
// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#include <SPI.h>
#endif
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
int BlueLed = 3;
int ClearLed = 4;
int RedLed = 5;
int GreenLed = 6;
int BlueLed2 = 7;
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 pairing 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);
PS4USB PS4(&Usb);
float SERVOFREQ = 50;
float pulseconstant;
boolean limit_reached = false;
int timer = 40;
void setup() {
Serial.begin(9600);
for ( int thispin = 3; thispin <7; thispin++) {
pinMode(thispin, OUTPUT);
}
pinMode(7,OUTPUT);
#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"));
pulseconstant = (1000000/SERVOFREQ)/4096;
pwm.begin();
pwm.setPWMFreq(SERVOFREQ);
}
void loop() {
Usb.Task();
if (PS4.connected()) {
limit_reached = false;
int LYValue;
LYValue = PS4.getAnalogHat(LeftHatY);
analogWrite(4, LYValue);
if (PS4.getButtonClick(CROSS)) {
Serial.print(F("\r\nCross "));
PS4.setLedFlash(10, 10); // Set it to blink rapidly
PS4.setRumbleOn(RumbleHigh);
Serial.print(PS4.getBatteryLevel());
}
}
Now I would like an led to blink when the cross is pressed. It should blink as many times as the voltage. ie: voltage reading = 9. llink led on off 9 times.