I am trying to write a code for my Portenta H7 that makes use of threading and the BLE component. The code is given below:
#include "Arduino.h"
#include "RPC.h"
//using namespace rtos;
rtos::Thread t1;
rtos::Thread t2;
String color;
BLEService ledService("19b10000-e8f2-537e-4f6c-d104768a1214");
BLEStringCharacteristic stringCharacteristic("19b10001-e8f2-537e-4f6c-d104768a1214", BLERead | BLEWrite, 20);
//LED Blink Functions---------------------------------------------------------------------------
void call_blue_led() {
digitalWrite(LEDB, LOW);
delay(500);
digitalWrite(LEDB, HIGH);
delay(500);
}
void call_red_led() {
digitalWrite(LEDR, LOW);
delay(500);
digitalWrite(LEDR, HIGH);
delay(500);
}
void call_green_led() {
digitalWrite(LEDG, LOW);
delay(500);
digitalWrite(LEDG, HIGH);
delay(500);
}
//----------------------------------------------------------------------------------------------
void setup() {
Serial.begin(9600);
pinMode(LEDR, OUTPUT);
pinMode(LEDG, OUTPUT);
pinMode(LEDB, OUTPUT);
if (!BLE.begin()) {
Serial.println("Starting Bluetooth® Low Energy failed!");
while (1);
}
BLE.setLocalName("LED-Controller");
BLE.setAdvertisedService(ledService);
ledService.addCharacteristic(stringCharacteristic);
BLE.addService(ledService);
stringCharacteristic.writeValue("Hello");
BLE.advertise();
Serial.println("BLE LED Control ready");
#ifdef CORE_CM7
bootM4();
// t1.start(call_red_led);
#endif
/*
#ifdef CORE_CM4
t2.start(call_green_led);
#endif
*/
}
void loop() {
if (central) {
Serial.print("Connected to central: ");
Serial.println(central.address());
while (central.connected()) {
if (stringCharacteristic.written()) {
color = stringCharacteristic.value();
Serial.println(color);
handleColorString(color);
}
}
Serial.print("Disconnected from central: ");
Serial.println(central.address());
}
if (color == "red") {
t1.start(call_red_led);
} else if (color == "green") {
t1.start(call_green_led);
} else if (color == "blue") {
t1.start(call_blue_led);
} else if (color == "off") {
digitalWrite(rLED, HIGH); // turn the LED off
digitalWrite(gLED, HIGH); // turn the LED off
digitalWrite(bLED, HIGH); // turn the LED off
} else {
Serial.println("Unknown color command received!");
}
}
when i try to complile the following lines give me an error:
"
BLEService ledService("19b10000-e8f2-537e-4f6c-d104768a1214");
BLEStringCharacteristic stringCharacteristic("19b10001-e8f2-537e-4f6c-d104768a1214", BLERead | BLEWrite, 20);
"
the error is:
"
Compilation error: 'BLEService' does not name a type
"
How do i resolve this issue