How to write 2 byte by modifying CallbackLED?

Hi, I changed the line
BLECharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite,4);
but is there anything I need to change? When I started the program, the data is 488D instead of 0.
When I type Serial.println(switchCharacteristic.value()); There is an error.
These two lines?
switchCharacteristic.setValue(0);
if (switchCharacteristic.value()) {

Here is the code with just changing
BLECharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite,4);

CallbackLED_twobyte:91:48: error: no matching function for call to 'println(const uint8_t*)'
Serial.println(switchCharacteristic.value());
^
Thanks,

CallbackLED_twobyte.ino (3.03 KB)

I have figured out, but is there any more BLE example out in the web?

/*
Callback LED

This example creates a BLE peripheral with service that contains a
characteristic to control an LED. The callback features of the
library are used.

The circuit:

  • Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT,
    Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board.

You can use a generic BLE central app, like LightBlue (iOS and Android) or
nRF Connect (Android), to interact with the services and characteristics
created in this sketch.

This example code is in the public domain.
*/

#include <ArduinoBLE.h>

BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // create service

// create switch characteristic and allow remote device to read and write
//BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
BLECharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite,4);

const int ledPin = LED_BUILTIN; // pin to use for the LED

void setup() {
Serial.begin(9600);
while (!Serial);

pinMode(ledPin, OUTPUT); // use the LED pin as an output

// begin initialization
if (!BLE.begin()) {
Serial.println("starting BLE failed!");

while (1);
}

// set the local name peripheral advertises
BLE.setLocalName("LEDCallback");
// set the UUID for the service this peripheral advertises
BLE.setAdvertisedService(ledService);

// add the characteristic to the service
ledService.addCharacteristic(switchCharacteristic);

// add service
BLE.addService(ledService);

// assign event handlers for connected, disconnected to peripheral
BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler);
BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);

// assign event handlers for characteristic
switchCharacteristic.setEventHandler(BLEWritten, switchCharacteristicWritten);
// set an initial value for the characteristic
// switchCharacteristic.setValue(0);
switchCharacteristic.writeValue((word)0x0201);

// start advertising
BLE.advertise();

Serial.println(("Bluetooth device active, waiting for connections..."));
}

void loop() {
// poll for BLE events
BLE.poll();
}

void blePeripheralConnectHandler(BLEDevice central) {
// central connected event handler
Serial.print("Connected event, central: ");
Serial.println(central.address());
}

void blePeripheralDisconnectHandler(BLEDevice central) {
// central disconnected event handler
Serial.print("Disconnected event, central: ");
Serial.println(central.address());
}

void switchCharacteristicWritten(BLEDevice central, BLECharacteristic characteristic) {
// central wrote new value to characteristic, update LED
Serial.print("Characteristic event, written: ");
word data;
switchCharacteristic.readValue(data);
// if (switchCharacteristic.value() &0xFFFF) {
if (data == 65535) {
Serial.println("LED on");
// Serial.println(switchCharacteristic.value());
Serial.println(data);
digitalWrite(ledPin, HIGH);
} else {
Serial.println("LED off");
// Serial.println(switchCharacteristic.value());
Serial.println(data);
digitalWrite(ledPin, LOW);
}
}

AK51school:
I have figured out, but is there any more BLE example out in the web?

There are examples in this forum. Are you looking for something specific?

Please read the How to use this forum to learn how to use code tags. It should looks like this.

Example code

Try to modify your post.