Add multiple lighting zones.
This commit is contained in:
parent
173c388b67
commit
f1dabd3a7d
2 changed files with 26 additions and 17 deletions
|
@ -2,22 +2,27 @@
|
||||||
#include <BLEUtils.h>
|
#include <BLEUtils.h>
|
||||||
|
|
||||||
class BluetoothLEDCallback : public BLECharacteristicCallbacks {
|
class BluetoothLEDCallback : public BLECharacteristicCallbacks {
|
||||||
LED *_led;
|
LED *_seatingLeds, *_kitchenLeds;
|
||||||
|
|
||||||
void onWrite(BLECharacteristic *characteristic) {
|
void onWrite(BLECharacteristic *characteristic) {
|
||||||
std::string value = characteristic->getValue();
|
std::string value = characteristic->getValue();
|
||||||
if (value.length() > 0) {
|
if (value.length() > 0) {
|
||||||
Serial.println(value.c_str());
|
Serial.println(value.c_str());
|
||||||
if (value == "on")
|
if (value == "seating on")
|
||||||
_led->on();
|
_seatingLeds->on();
|
||||||
else
|
if (value == "kitchen on")
|
||||||
_led->off();
|
_kitchenLeds->on();
|
||||||
|
if (value == "seating off")
|
||||||
|
_seatingLeds->off();
|
||||||
|
if (value == "kitchen off")
|
||||||
|
_kitchenLeds->off();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
BluetoothLEDCallback(LED* led){
|
BluetoothLEDCallback(LED *seatingLeds, LED *kitchenLeds){
|
||||||
_led = led;
|
_seatingLeds = seatingLeds;
|
||||||
|
_kitchenLeds = kitchenLeds;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
22
src/main.cpp
22
src/main.cpp
|
@ -6,24 +6,28 @@
|
||||||
#define FADE_IN_DURATION 500
|
#define FADE_IN_DURATION 500
|
||||||
#define FADE_OUT_DURATION 2000
|
#define FADE_OUT_DURATION 2000
|
||||||
|
|
||||||
LEDOutput _ledOutput(0, true);
|
LEDOutput _seatingLedOutput(0, true);
|
||||||
LED _led(&_ledOutput, FADE_IN_DURATION, FADE_OUT_DURATION);
|
LED _seatingLeds(&_seatingLedOutput, FADE_IN_DURATION, FADE_OUT_DURATION);
|
||||||
|
LEDOutput _kitchenLedOutput(1 , true);
|
||||||
|
LED _kitchenLeds(&_kitchenLedOutput, FADE_IN_DURATION, FADE_OUT_DURATION);
|
||||||
|
|
||||||
BluetoothLEDCallback _btCallback(&_led);
|
BluetoothLEDCallback _btCallback(&_seatingLeds, &_kitchenLeds);
|
||||||
BluetoothService _btService("Van Lights", &_btCallback);
|
BluetoothService _btService("Van Lights", &_btCallback);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
_ledOutput.attach(16);
|
_seatingLedOutput.attach(16);
|
||||||
_ledOutput.attach(17);
|
_seatingLedOutput.attach(17);
|
||||||
_ledOutput.attach(5);
|
|
||||||
_ledOutput.attach(18);
|
_kitchenLedOutput.attach(5);
|
||||||
_ledOutput.attach(23);
|
_kitchenLedOutput.attach(18);
|
||||||
|
_kitchenLedOutput.attach(23);
|
||||||
|
|
||||||
_btService.init();
|
_btService.init();
|
||||||
_btService.start();
|
_btService.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
_led.loop();
|
_seatingLeds.loop();
|
||||||
|
_kitchenLeds.loop();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue