I am new to Adruino and have tried to use ChatGPT for the code. But I can't seem to connect my Bluetooth controller, and doesn't want to bring up the MAC address of controller in Serial Monitor. It keeps saying: PS4 Bluetooth Library Started
This is the code:
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>
#include <PS4Controller.h>
#include <ps4.h>
#include <ps4_int.h>
#include <BTAddress.h>
#include <BTAdvertisedDevice.h>
#include <BTScan.h>
#include <BluetoothSerial.h>
#include <PS4Controller.h>
// Replace with your PS4 controller's MAC address
const char *ps4MACAddress = "e4:65:b8:e7:2c:a4";
// Callback functions
void onConnect() {
Serial.println("PS4 Controller connected!");
Serial.println(PS4.isConnected());
}
void onDisconnect() {
Serial.println("PS4 Controller disconnected!");
}
void setup() {
Serial.begin(115200);
PS4.attach(onConnect);
PS4.attachOnDisconnect(onDisconnect);
if (PS4.begin(ps4MACAddress)) {
Serial.println("PS4 Bluetooth Library Started");
} else {
Serial.println("Failed to start PS4 Bluetooth Library");
}
}
void loop() {
if (PS4.isConnected()) {
// Example: Print the analog stick values
Serial.print("Left Stick: ");
Serial.print(PS4.LStickX());
Serial.print(", ");
Serial.println(PS4.LStickY());
Serial.print("Right Stick: ");
Serial.print(PS4.RStickX());
Serial.print(", ");
Serial.println(PS4.RStickY());
delay(100); // Add a delay to avoid flooding the serial output
}
Serial Monitor Problem (No MAC address):
14:01:45.426 -> ets Jul 29 2019 12:21:46
14:01:45.426 ->
14:01:45.426 -> rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
14:01:45.467 -> configsip: 0, SPIWP:0xee
14:01:45.467 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
14:01:45.467 -> mode:DIO, clock div:1
14:01:45.467 -> load:0x3fff0030,len:1448
14:01:45.467 -> load:0x40078000,len:14844
14:01:45.467 -> ho 0 tail 12 room 4
14:01:45.467 -> load:0x40080400,len:4
14:01:45.467 -> load:0x40080404,len:3356
14:01:45.467 -> entry 0x4008059c
14:01:46.272 -> PS4 Bluetooth Library Started