#include <ArduinoBLE.h>
#include <Arduino_LSM6DS3.h>const int ledPin = LED_BUILTIN; // set ledPin to on-board LED
const int buttonPin = 4; // set buttonPin to digital pin 4BLEService ledService(“19B10010-E8F2-537E-4F6C-D104768A1214”); // create service
// create switch characteristic and allow remote device to read and write
BLEByteCharacteristic ledCharacteristic(“19B10011-E8F2-537E-4F6C-D104768A1214”, BLERead | BLEWrite);
// create button characteristic and allow remote device to get notifications
BLEByteCharacteristic buttonCharacteristic(“19B10012-E8F2-537E-4F6C-D104768A1214”, BLERead | BLENotify);void setup() {
Serial.begin(9600);
while (!Serial);pinMode(ledPin, OUTPUT); // use the LED as an output
pinMode(buttonPin, INPUT); // use button pin as an input// begin initialization
if (!BLE.begin()) {
Serial.println(“starting BLE failed!”);while (1);
}
if (!IMU.begin()) {
Serial.println(“Failed to initialize IMU!”);while (1);
}// set the local name peripheral advertises
BLE.setLocalName(“ButtonLED”);
// set the UUID for the service this peripheral advertises:
BLE.setAdvertisedService(ledService);// add the characteristics to the service
ledService.addCharacteristic(ledCharacteristic);
ledService.addCharacteristic(buttonCharacteristic);// add the service
BLE.addService(ledService);ledCharacteristic.writeValue(0);
buttonCharacteristic.writeValue(0);// start advertising
BLE.advertise();Serial.println(“Bluetooth device active, waiting for connections…”);
}void loop() {
BLEDevice central = BLE.central();if (central) {
Serial.print(“Connected to central: “);
// print the central’s BT address:
Serial.println(central.address());
}while (central.connected()) {
BLE.poll();
float x, y, z;if (IMU.accelerationAvailable()) {
IMU.readAcceleration(x, y, z);Serial.println(y);
if (ledCharacteristic.value()) {
Serial.println(“LED on”);
digitalWrite(ledPin, HIGH);
}
else {
Serial.println(“LED off”);
digitalWrite(ledPin, LOW);
}
}
}
if(!central) {
Serial.print(“Disconnected to centeral:”);
Serial.println(central.address());
}
}
I have a screen recording but I cannot get it to load into this post