This sketch compiles on the 1.8.12 IDE, but not the 2.0.4.
Compilation error: ArduinoBLE.h: No such file or directory
I was able to specify the Nano BLE 33 board on both IDE's. Why won't the sketch compile on the 2.0.4 IDE? Thanks.
#include <ArduinoBLE.h>
enum {
DIRECTION_NONE = 0,
DIRECTION_LEFT = 1,
DIRECTION_RIGHT = 2
};
const char* deviceServiceUuid = "xxxx0000-e8f2-537e-4f6c-d104768a1214";
const char* deviceServiceCharacteristicUuid = "xxxx0001-e8f2-537e-4f6c-d104768a1214";
int roverDirection=0;
BLEService directionService(deviceServiceUuid);
BLEByteCharacteristic directionCharacteristic(deviceServiceCharacteristicUuid, BLERead | BLEWrite);
void setup() {
Serial.begin(115200);
while (!Serial);
if (!BLE.begin()) {
Serial.println("- Starting Bluetooth® Low Energy module failed!");
while (1);
}
BLE.setLocalName("Arduino Nano 33 BLE (Peripheral)");
BLE.setAdvertisedService(directionService);
directionService.addCharacteristic(directionCharacteristic);
BLE.addService(directionService);
directionCharacteristic.writeValue(0);
BLE.advertise();
Serial.println("Nano 33 BLE (Peripheral Device)");
Serial.println(" ");
}
void loop() {
BLEDevice central = BLE.central();
Serial.println("- Discovering central device...");
delay(500);
if (central) {
Serial.println("* Connected to central device!");
Serial.print("* Device MAC address: ");
Serial.println(central.address());
Serial.println(" ");
while (central.connected()) {
if (directionCharacteristic.written()) {
roverDirection = directionCharacteristic.value();
writeDirection(roverDirection);
}
}
Serial.println("* Disconnected to central device!");
}
}
void writeDirection(int roverDirection) {
Serial.println("- Characteristic <direction_type> has changed!");
switch (roverDirection) {
case DIRECTION_LEFT:
Serial.println("* Actual value: LEFT ");
// do something
break;
case DIRECTION_RIGHT:
Serial.println("* Actual value: RIGHT ");
Serial.println(" ");
// do something
break;
default:
Serial.println("* Actual value: DEFAULT ");
// do something
break;
}
}