I was able to get this working, but I was curious how the code would need to change if I wanted to control more than one LED. My first instinct would be to send different values for each LED to the arduino and use if statements to distinguish which LED I was looking to change and which pin to address, but I didn't know if you were able to send values other than 0 or 1 to the board. If someone could explain how I can go about doing this, that would be great.
There are a couple of ways to do this.
1 - create additional characteristics for the additional LEDs.
2 - use a single characteristic and use codes for the additional LEDS.
Each LED would have its own characteristic and the on/off value would be 0/1 for all LEDs.
Each addition characteristic needs to use a unique UUID so LED #2 would be 19B10002-E8F2-537E-4F6C-D104768A1214 and LED 3 would be 19B10003-E8F2-537E-4F6C-D104768A1214
Each char needs to have a unique reference, like
BLEUnsignedCharCharacteristic switch1Characteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
BLEUnsignedCharCharacteristic switch2Characteristic("19B10002-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
BLEUnsignedCharCharacteristic switch3Characteristic("19B10003-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
You then have checks for each switch characteristic.
#2 is probably the easiest but maybe not inline with the intentions of BLE.
Just use additional values for the other LEDs; 0/1 for LED1, 2/3 for LED 2 and 4/5 for LED3
you then extend the following section
if (switchCharacteristic.value())
{
digitalWrite(ledPin, HIGH);
}
//else turn the LED off
else
{
digitalWrite(ledPin, LOW);
}
to something like this (not tested):
if (switchCharacteristic.value() == 0) { digitalWrite(led1Pin, LOW); }
else if (switchCharacteristic.value() == 1) { digitalWrite(led1Pin, HIGH); }
else if (switchCharacteristic.value() == 2) { digitalWrite(led2Pin, LOW); }
else if (switchCharacteristic.value() == 3) { digitalWrite(led2Pin, HIGH); }
else if (switchCharacteristic.value() == 4) { digitalWrite(led3Pin, LOW); }
else if (switchCharacteristic.value() == 5) { digitalWrite(led4Pin, HIGH); }