Compare commits
2 Commits
a7cf62b9eb
...
8f601ec030
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8f601ec030 | ||
|
|
8b2a97b364 |
39
src/lightingFirmware/SimpleBleDevice/SimpleBleDevice.ino
Normal file
39
src/lightingFirmware/SimpleBleDevice/SimpleBleDevice.ino
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#include <BLEDevice.h>
|
||||||
|
#include <BLEUtils.h>
|
||||||
|
#include <BLEServer.h>
|
||||||
|
|
||||||
|
// See the following for generating UUIDs:
|
||||||
|
// https://www.uuidgenerator.net/
|
||||||
|
|
||||||
|
#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
|
||||||
|
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.println("Starting BLE work!");
|
||||||
|
|
||||||
|
BLEDevice::init("Long name works now");
|
||||||
|
BLEServer *pServer = BLEDevice::createServer();
|
||||||
|
BLEService *pService = pServer->createService(SERVICE_UUID);
|
||||||
|
BLECharacteristic *pCharacteristic = pService->createCharacteristic(
|
||||||
|
CHARACTERISTIC_UUID,
|
||||||
|
BLECharacteristic::PROPERTY_READ |
|
||||||
|
BLECharacteristic::PROPERTY_WRITE
|
||||||
|
);
|
||||||
|
|
||||||
|
pCharacteristic->setValue("Hello World says Neil");
|
||||||
|
pService->start();
|
||||||
|
// BLEAdvertising *pAdvertising = pServer->getAdvertising(); // this still is working for backward compatibility
|
||||||
|
BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
|
||||||
|
pAdvertising->addServiceUUID(SERVICE_UUID);
|
||||||
|
pAdvertising->setScanResponse(true);
|
||||||
|
pAdvertising->setMinPreferred(0x06); // functions that help with iPhone connections issue
|
||||||
|
pAdvertising->setMinPreferred(0x12);
|
||||||
|
BLEDevice::startAdvertising();
|
||||||
|
Serial.println("Characteristic defined! Now you can read it in your phone!");
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// put your main code here, to run repeatedly:
|
||||||
|
delay(2000);
|
||||||
|
}
|
||||||
6
src/lightingFirmware/SimpleBleDevice/ci.json
Normal file
6
src/lightingFirmware/SimpleBleDevice/ci.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"requires": [
|
||||||
|
"CONFIG_BT_ENABLED=y",
|
||||||
|
"CONFIG_BLUEDROID_ENABLED=y"
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -1,18 +1,44 @@
|
|||||||
// Include Section
|
// Include Section
|
||||||
|
|
||||||
#include "esp_dmx.h"
|
#include "esp_dmx.h"
|
||||||
|
#include "BluetoothSerial.h"
|
||||||
|
#include <BLEDevice.h>
|
||||||
|
#include <BLEUtils.h>
|
||||||
|
#include <BLEServer.h>
|
||||||
|
|
||||||
|
// Name of Bluetooth client.
|
||||||
|
String BTDeviceName = "3D_SkyLED_LEDBoard";
|
||||||
|
String BTMacAddress;
|
||||||
|
// Check if Bluetooth is available.
|
||||||
|
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
|
||||||
|
#error Bluetooth is not enabled!
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Check if Serial Port Profile (SPP) is available.
|
||||||
|
#if !defined(CONFIG_BT_SPP_ENABLED)
|
||||||
|
#error Serial Port Profile for Bluetooth is not available or not enabled!
|
||||||
|
#endif
|
||||||
// Define Section
|
// Define Section
|
||||||
|
#define BT_DISCOVER_TIME 30000
|
||||||
#define ledPin 2
|
|
||||||
#define INTERRUPT_PIN 0
|
#define INTERRUPT_PIN 0
|
||||||
|
|
||||||
|
BluetoothSerial SerialBT;
|
||||||
|
char btmessage;
|
||||||
|
|
||||||
struct Button {
|
struct Button {
|
||||||
const uint8_t PIN;
|
const uint8_t PIN;
|
||||||
uint32_t numberKeyPresses;
|
uint32_t numberKeyPresses;
|
||||||
bool pressed;
|
bool pressed;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Panel {
|
||||||
|
int led0;
|
||||||
|
int led1;
|
||||||
|
int led2;
|
||||||
|
int led3;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// Defining BOOT button on ESP32 as our built-in button.
|
// Defining BOOT button on ESP32 as our built-in button.
|
||||||
Button button1 = {INTERRUPT_PIN, 0, false};
|
Button button1 = {INTERRUPT_PIN, 0, false};
|
||||||
|
|
||||||
@ -148,7 +174,7 @@ uint8_t dataSeq[modeAmount][DMX_PACKET_SIZE] =
|
|||||||
{
|
{
|
||||||
0,
|
0,
|
||||||
//Start Inner Round
|
//Start Inner Round
|
||||||
universalBrightness,0,0,0,
|
0,0,universalBrightness,0,
|
||||||
0,0,0,0,
|
0,0,0,0,
|
||||||
0,0,0,0,
|
0,0,0,0,
|
||||||
0,0,0,0,
|
0,0,0,0,
|
||||||
@ -209,30 +235,30 @@ void dmxSetup() {
|
|||||||
Serial.print("Done");
|
Serial.print("Done");
|
||||||
|
|
||||||
// ...and then set the communication pins!
|
// ...and then set the communication pins!
|
||||||
const int tx_pin = 18;
|
const int tx_pin = 23;
|
||||||
const int rx_pin = 5;
|
const int rx_pin = 22;
|
||||||
const int rts_pin = 21;
|
const int rts_pin = 21;
|
||||||
Serial.printf("\nSetting up pin %d as Transmit Pin, pin %d as Receive Pin and pin %d as RTS Pin... ", tx_pin, rx_pin, rts_pin);
|
Serial.printf("\nSetting up pin %d as Transmit Pin, pin %d as Receive Pin and pin %d as RTS Pin... ", tx_pin, rx_pin, rts_pin);
|
||||||
dmx_set_pin(dmx_num, tx_pin, rx_pin, rts_pin);
|
dmx_set_pin(dmx_num, tx_pin, rx_pin, rts_pin);
|
||||||
Serial.print("Done\n");
|
Serial.print("Done\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int serialRead(){
|
void serialRead(){
|
||||||
int incomingByte;
|
String incomingByte;
|
||||||
if (Serial.available() > 0) {
|
if (Serial.available() > 0) {
|
||||||
// read the incoming byte:
|
// read the incoming byte:
|
||||||
incomingByte = Serial.read();
|
incomingByte = Serial.readStringUntil('\r\n');
|
||||||
|
Serial.print("\nI received: ");
|
||||||
// say what you got:
|
Serial.print(incomingByte);
|
||||||
Serial.print("I received: ");
|
mode = incomingByte.toInt();
|
||||||
Serial.println(incomingByte, DEC);
|
|
||||||
}
|
}
|
||||||
return incomingByte;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
pinMode(ledPin,OUTPUT);
|
SerialBT.begin(BTDeviceName);
|
||||||
|
BTMacAddress = SerialBT.getBtAddressString();
|
||||||
|
Serial.println(BTMacAddress.c_str());
|
||||||
pinMode(INTERRUPT_PIN, INPUT_PULLUP);
|
pinMode(INTERRUPT_PIN, INPUT_PULLUP);
|
||||||
attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), isr, RISING);
|
attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), isr, RISING);
|
||||||
delay(2000);
|
delay(2000);
|
||||||
@ -247,11 +273,16 @@ void loop() {
|
|||||||
// Preparing next packet
|
// Preparing next packet
|
||||||
if (button1.pressed){
|
if (button1.pressed){
|
||||||
if (mode < modeAmount - 1){mode++;} else {mode = 0;};
|
if (mode < modeAmount - 1){mode++;} else {mode = 0;};
|
||||||
Serial.printf("\n Changing to mode %d", mode); // Increment the value of each slot, excluding the start code.
|
Serial.printf("\nChanging to mode %d", mode); // Increment the value of each slot, excluding the start code.
|
||||||
button1.pressed = false; // Reset button status to FALSE
|
button1.pressed = false; // Reset button status to FALSE
|
||||||
};
|
};
|
||||||
// Wait until the packet is finished being sent before proceeding.
|
// Wait until the packet is finished being sent before proceeding.
|
||||||
dmx_wait_sent(DMX_NUM_1, DMX_TIMEOUT_TICK);
|
dmx_wait_sent(DMX_NUM_1, DMX_TIMEOUT_TICK);
|
||||||
// Now write the packet synchronously!
|
// Now write the packet synchronously!
|
||||||
dmx_write(DMX_NUM_1, dataSeq[mode], 100);
|
dmx_write(DMX_NUM_1, dataSeq[mode], 100);
|
||||||
|
serialRead();
|
||||||
|
if (SerialBT.available()) {
|
||||||
|
btmessage=SerialBT.read();
|
||||||
|
Serial.print(btmessage);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user