#include "NDP.h" #include // BLE Service & Characteristic UUIDs BLEService matchService("12345678-1234-1234-1234-1234567890AB"); BLEByteCharacteristic matchChar("87654321-4321-4321-4321-BA0987654321", BLERead | BLENotify); volatile uint8_t matchID = 0; // ID für Match // Callback bei Match void sendMatch(char* label) { // LED blau bei Match nicla::leds.begin(); nicla::leds.setColor(blue); delay(200); nicla::leds.setColor(off); nicla::leds.end(); // Byte setzen if (strcmp(label, "NN0:Helmet") == 0) matchID = 0x01; else if (strcmp(label, "NN0:Iron Man") == 0) matchID = 0x02; else if (strcmp(label, "NN0:Shutdown") == 0) matchID = 0x03; else if (strcmp(label, "NN0:Startup") == 0) matchID = 0x04; else if (strcmp(label, "NN0:Repulsor") == 0) matchID = 0x05; else if (strcmp(label, "NN0:Stones") == 0) matchID = 0x06; else if (strcmp(label, "NN0:Combat") == 0) matchID = 0x07; } void setup() { Serial.begin(115200); // Nicla Setup nicla::begin(); nicla::disableLDO(); nicla::leds.begin(); NDP.onMatch(sendMatch); NDP.begin("mcu_fw_120_v91.synpkg"); NDP.load("dsp_firmware_v91.synpkg"); NDP.load("ei_model.synpkg"); NDP.turnOnMicrophone(); NDP.interrupts(); // BLE starten if (!BLE.begin()) { Serial.println("BLE failed!"); while (1); } BLE.setLocalName("NiclaVoiceBLE"); BLE.setAdvertisedService(matchService); matchService.addCharacteristic(matchChar); BLE.addService(matchService); BLE.advertise(); Serial.println("BLE Peripheral started"); } void loop() { BLEDevice central = BLE.central(); if (central) { Serial.print("Connected to central: "); Serial.println(central.address()); while (central.connected()) { if (matchID != 0) { matchChar.writeValue(matchID); // sendet das Byte automatisch über BLE Serial.print("Sent matchID: 0x"); Serial.println(matchID, HEX); matchID = 0; // zurücksetzen, damit nicht mehrfach gesendet wird } } Serial.println("Central disconnected"); } }