the board is a 33 IoT. See last line of this thread.
#include <ArduinoBLE.h>
BLEService ledService("180A"); // BLE LED Service
// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central
BLEByteCharacteristic switchCharacteristic("2A57", BLERead | BLEWrite);
const int LEDR = LEDR;
const int LEDG = LEDG;
const int LEDB = LEDB;
void setup() {
Serial.begin(9600);
while (!Serial);
// set LED's pin to output mode
pinMode(LEDR, OUTPUT);
pinMode(LEDG, OUTPUT);
pinMode(LEDB, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW); // when the central disconnects, turn off the LED
digitalWrite(LEDR, HIGH); // will turn the LED off
digitalWrite(LEDG, HIGH); // will turn the LED off
digitalWrite(LEDB, HIGH); // will turn the LED off
// begin initialization
if (!BLE.begin()) {
Serial.println("starting Bluetooth® Low Energy failed!");
while (1);
}
// set advertised local name and service UUID:
BLE.setLocalName("Nano 33 BLE");
BLE.setAdvertisedService(ledService);
// add the characteristic to the service
ledService.addCharacteristic(switchCharacteristic);
// add service
BLE.addService(ledService);
// set the initial value for the characteristic:
switchCharacteristic.writeValue(0);
// start advertising
BLE.advertise();
Serial.println("BLE LED Peripheral");
}
void loop() {
// listen for BLE peripherals to connect:
BLEDevice central = BLE.central();
// if a central is connected to peripheral:
if (central) {
Serial.print("Connected to central: ");
// print the central's MAC address:
Serial.println(central.address());
digitalWrite(LED_BUILTIN, HIGH); // turn on the LED to indicate the connection
// while the central is still connected to peripheral:
while (central.connected()) {
// if the remote device wrote to the characteristic,
// use the value to control the LED:
if (switchCharacteristic.written()) {
switch (switchCharacteristic.value()) { // any value other than 0
case 01:
Serial.println("Red LED on");
digitalWrite(LEDR, LOW); // will turn the LED on
digitalWrite(LEDG, HIGH); // will turn the LED off
digitalWrite(LEDB, HIGH); // will turn the LED off
break;
case 02:
Serial.println("Green LED on");
digitalWrite(LEDR, HIGH); // will turn the LED off
digitalWrite(LEDG, LOW); // will turn the LED on
digitalWrite(LEDB, HIGH); // will turn the LED off
break;
case 03:
Serial.println("Blue LED on");
digitalWrite(LEDR, HIGH); // will turn the LED off
digitalWrite(LEDG, HIGH); // will turn the LED off
digitalWrite(LEDB, LOW); // will turn the LED on
break;
default:
Serial.println(F("LEDs off"));
digitalWrite(LEDR, HIGH); // will turn the LED off
digitalWrite(LEDG, HIGH); // will turn the LED off
digitalWrite(LEDB, HIGH); // will turn the LED off
break;
}
}
}
// when the central disconnects, print it out:
Serial.print(F("Disconnected from central: "));
Serial.println(central.address());
digitalWrite(LED_BUILTIN, LOW); // when the central disconnects, turn off the LED
digitalWrite(LEDR, HIGH); // will turn the LED off
digitalWrite(LEDG, HIGH); // will turn the LED off
digitalWrite(LEDB, HIGH); // will turn the LED off
}
}
this is the code I took from the link above with my small addition that allows it to compile
const int LEDR = LEDR;
const int LEDG = LEDG;
const int LEDB = LEDB;
this is the sketch that partially works, it updates the serial monitor when I send a code using my mobile and the software recommended in the link above, lightblue.
if I alter it, comment out the 3 lines above and replace them with
//#define PIN_LED (13u)
#define LED_BUILTIN PIN_LED
#define LEDR (22u)
#define LEDG (23u)
#define LEDB (24u)
#define LED_PWR (25u)
I commented out the first line as the compile doesn't seem to like that one?
Now when I run it it is ok when I send 3 (the code for the blue led) but crashes if I send 1 (the code for the red led). At least it still shows the send on the monitor but the leds on the unit don't change.
I have a green led one side of the usb plug and a yellow one the other side, is one of these supposed to be the multi coloured led?
Does the 33IoT not have a multi-coloured led? Am I barking up the wrong tree?