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 "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 ledPin 2
|
||||
#define BT_DISCOVER_TIME 30000
|
||||
#define INTERRUPT_PIN 0
|
||||
|
||||
BluetoothSerial SerialBT;
|
||||
char btmessage;
|
||||
|
||||
struct Button {
|
||||
const uint8_t PIN;
|
||||
uint32_t numberKeyPresses;
|
||||
bool pressed;
|
||||
};
|
||||
|
||||
struct Panel {
|
||||
int led0;
|
||||
int led1;
|
||||
int led2;
|
||||
int led3;
|
||||
};
|
||||
|
||||
|
||||
// Defining BOOT button on ESP32 as our built-in button.
|
||||
Button button1 = {INTERRUPT_PIN, 0, false};
|
||||
|
||||
@ -148,7 +174,7 @@ uint8_t dataSeq[modeAmount][DMX_PACKET_SIZE] =
|
||||
{
|
||||
0,
|
||||
//Start Inner Round
|
||||
universalBrightness,0,0,0,
|
||||
0,0,universalBrightness,0,
|
||||
0,0,0,0,
|
||||
0,0,0,0,
|
||||
0,0,0,0,
|
||||
@ -209,30 +235,30 @@ void dmxSetup() {
|
||||
Serial.print("Done");
|
||||
|
||||
// ...and then set the communication pins!
|
||||
const int tx_pin = 18;
|
||||
const int rx_pin = 5;
|
||||
const int tx_pin = 23;
|
||||
const int rx_pin = 22;
|
||||
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);
|
||||
dmx_set_pin(dmx_num, tx_pin, rx_pin, rts_pin);
|
||||
Serial.print("Done\n");
|
||||
}
|
||||
|
||||
int serialRead(){
|
||||
int incomingByte;
|
||||
void serialRead(){
|
||||
String incomingByte;
|
||||
if (Serial.available() > 0) {
|
||||
// read the incoming byte:
|
||||
incomingByte = Serial.read();
|
||||
|
||||
// say what you got:
|
||||
Serial.print("I received: ");
|
||||
Serial.println(incomingByte, DEC);
|
||||
incomingByte = Serial.readStringUntil('\r\n');
|
||||
Serial.print("\nI received: ");
|
||||
Serial.print(incomingByte);
|
||||
mode = incomingByte.toInt();
|
||||
}
|
||||
return incomingByte;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
pinMode(ledPin,OUTPUT);
|
||||
SerialBT.begin(BTDeviceName);
|
||||
BTMacAddress = SerialBT.getBtAddressString();
|
||||
Serial.println(BTMacAddress.c_str());
|
||||
pinMode(INTERRUPT_PIN, INPUT_PULLUP);
|
||||
attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), isr, RISING);
|
||||
delay(2000);
|
||||
@ -247,11 +273,16 @@ void loop() {
|
||||
// Preparing next packet
|
||||
if (button1.pressed){
|
||||
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
|
||||
};
|
||||
// Wait until the packet is finished being sent before proceeding.
|
||||
dmx_wait_sent(DMX_NUM_1, DMX_TIMEOUT_TICK);
|
||||
// Now write the packet synchronously!
|
||||
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