Arduino, ethertnet y pca9685

Buen dia

Estoy trabajando en un proyecto en el cual debo encender unas cintas led con diferentes colores enviando un comando por TCP IP, pero tengo un inconveniente es que necesito que mi arduino no se quede en un loop si no que pueda recibir comandos con el color. adjunto envio una parte del codigo tnego que controlar 5 cintas led lo hago con un PCA 9685, no se si alguien ya tenga algun proyecto base ya ralizado o que me recomiendan , investigue algo sobre photothreadas y freertos pero no tengo conocimiento de programacion en estas librerias.

#include <WiFiServer.h>
#include <WiFiServerSecure.h>
#include <WiFiUdp.h>

#include <Adafruit_PWMServoDriver.h>

Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x40);

String pedido;
String respuesta;
String id_device = "001";
String OFF = "OFF12345"; //TODO APAGADO
String DND = "DND12345"; //NO MOLESTAR
String CHK = "CHK12345"; //CHECK OUT
String ASE = "ASE12345"; //ASEO
String ROO = "ROO12345"; //ROOM SERVICE
String CAM = "CAM12345"; //CAMARERIA
String TES = "TES12345"; //TEST
String ASR = "QCL12345"; //ASEO RAPIDO
String ALL = "ALL12345"; //TODO
String MTO = "MTO12345"; //MANTENIMIENTO
String CAD = "CAD12345"; //CAMARERA DEMORADA
String ROM = "ROM12345"; //ROMANTICO
String ASI = "ASI12345"; //ASIGNADA
String DNDA = "DNA12345"; //DND ASIGNADA
String ASEA = "CLA12345"; // ASEO ASIGNADA
String ROOA = "ROA12345"; //ROOM SERVICE ASIGNADA
String CAMA = "MAA12345"; //CAMARERIA ASIGNADA
String ASRA = "QCA12345"; //ASEO RAPIDO ASIGNADA
String CADA = "DAA12345"; //CAMARERA DEMORADA ASIGNADA
String DNDC = "DNC12345"; //DND CHECK OUT
String ASEC = "ASC12345"; //ASEO CHECK OUT
String ROOC = "ROC12345"; //ROOM SERVICE CHECK OUT
String CAMC = "CAC12345"; //CAMARERIA CHECK OUT
String CADC = "CDC12345"; //ASEO RAPIDO CHECK OUT
String DNDAS = "DAS12345"; //DND ASIGNADA ASEO
const char* ssid = "Marbella";
const char* password = "reservas123";
const char* host = "172.10.10.225";

WiFiServer server(49100);

void setup() {
Serial.begin(115200);
delay(10);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.begin(ssid, password);
IPAddress ip(172, 10, 10, 23);
IPAddress gateway(172, 10, 10, 2);
IPAddress subnet(255, 255, 255, 0);
WiFi.config(ip, gateway, subnet);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");

// Start the server
server.begin();
Serial.println("Server started");

// Print the IP address
Serial.print("Use this URL to connect: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
ArduinoOTA.begin();

Serial.println("GPIO test!");
Serial.println("Ready");
pwm.begin();
pwm.setPWMFreq(1000);

// if you want to really speed stuff up, you can go into 'fast 400khz I2C' mode
// some i2c devices dont like this so much so if you're sharing the bus, watch
// out for this!
Wire.setClock(100000);
}

void loop() {

ArduinoOTA.handle();
// Check if a client has connected
respuesta = "";
WiFiClient client = server.available();
if (!client) {
return;
}

// Wait until the client sends some data
Serial.println("Hab 609");
while (!client.available()) {
delay(1);
}

// Read the first line of the request
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();

pedido = request.substring(5, 13);

if (request.substring(0, 2) == "=" && request.substring(2, 5) == id_device && request.substring(5, 13) == OFF && request.substring(13) == "=") { //OFF (HABITACIÓN DISPONIBLE)
for (uint8_t pin = 0; pin <= 15; pin++) {
pwm.setPWM(pin, 0, 4096);
}
}
pwm.setPWM(8, 0, 4095);
if (request.substring(0, 2) == "=" && request.substring(2, 5) == id_device && request.substring(5, 13) == DND && request.substring(13) == "=") { //NO MOLESTAR (ROJO DND)
for (uint8_t pin = 0; pin <= 15; pin++) {
pwm.setPWM(pin, 0, 4096);
}
pwm.setPWM(15, 0, 4095);
}
if (request.substring(0, 2) == "=" && request.substring(2, 5) == id_device && request.substring(5, 13) == CHK && request.substring(13) == "=") { //CHECK OUT (VERDE NOM)
for (uint8_t pin = 0; pin <= 15; pin++) {
pwm.setPWM(pin, 0, 4096);
}
}
if (request.substring(0, 2) == "=" && request.substring(2, 5) == id_device && request.substring(5, 13) == ASE && request.substring(13) == "=") { //REQUIERE ASEO (VERDE ASEO)
for (uint8_t pin = 0; pin <= 15; pin++) {
pwm.setPWM(pin, 0, 4096);
}
pwm.setPWM(5, 0, 4095);
}
if (request.substring(0, 2) == "=" && request.substring(2, 5) == id_device && request.substring(5, 13) == ROO && request.substring(13) == "=") { //REQUIERE ROOM SERVICE (AZUL ROOM)
for (uint8_t pin = 0; pin <= 15; pin++) {
pwm.setPWM(pin, 0, 4096);
}
pwm.setPWM(10, 0, 4095);
}
if (request.substring(0, 2) == "=" && request.substring(2, 5) == id_device && request.substring(5, 13) == CAM && request.substring(13) == "=") { //EN CAMARERÍA (AMARILLO CAMARERÍA)
for (uint8_t pin = 0; pin <= 15; pin++) {
pwm.setPWM(pin, 0, 4096);
}
pwm.setPWM(3, 0, 4000);
pwm.setPWM(2, 0, 2000);
}
if (request.substring(0, 2) == "=" && request.substring(2, 5) == id_device && request.substring(5, 13) == TES && request.substring(13) == "=") { //TEST (TODO ENCENDIDO)
for (uint8_t pin = 0; pin <= 15; pin++) {
pwm.setPWM(pin, 0, 4095);
}
}
if (request.substring(0, 2) == "=" && request.substring(2, 5) == id_device && request.substring(5, 13) == ASR && request.substring(13) == "=") { //REQUIERE ASEO PRIORITARIO (ROJO ASEO)
for (uint8_t pin = 0; pin <= 15; pin++) {
pwm.setPWM(pin, 0, 4096);
}
pwm.setPWM(6, 0, 4095);
}
if (request.substring(0, 2) == "=" && request.substring(2, 5) == id_device && request.substring(5, 13) == ALL && request.substring(13) == "=") { //HABITACIÓN EN MANTENIMIENTO (AMARILLO DND Y ASEO)
for (uint8_t pin = 0; pin <= 15; pin++) {
pwm.setPWM(pin, 0, 4096);
}
pwm.setPWM(15, 0, 4095);
pwm.setPWM(10, 0, 4095);
pwm.setPWM(5, 0, 4095);
pwm.setPWM(2, 0, 2000);
pwm.setPWM(3, 0, 4000);
for (uint8_t pin = 7; pin <= 9; pin++) {
pwm.setPWM(pin, 0, 4095);
}
}
if (request.substring(0, 2) == "=" && request.substring(2, 5) == id_device && request.substring(5, 13) == MTO && request.substring(13) == "=") { //HABITACIÓN EN MANTENIMIENTO (AMARILLO DND Y ASEO)
for (uint8_t pin = 0; pin <= 15; pin++) {
pwm.setPWM(pin, 0, 4096);
}
pwm.setPWM(15, 0, 4000);
pwm.setPWM(14, 0, 2000);
pwm.setPWM(6, 0, 4000);
pwm.setPWM(5, 0, 2000);
}
if (request.substring(0, 2) == "=" && request.substring(2, 5) == id_device && request.substring(5, 13) == CAD && request.substring(13) == "=") { //CAMARERA DEMORADA (ROJO CAMARERÍA)
for (uint8_t pin = 0; pin <= 15; pin++) {
pwm.setPWM(pin, 0, 4096);
}
pwm.setPWM(3, 0, 4095);
}
if (request.substring(0, 2) == "=" && request.substring(2, 5) == id_device && request.substring(5, 13) == ROM && request.substring(13) == "=") { //ROMÁNTICO (TODO EN ROSADO)
for (uint8_t pin = 0; pin <= 15; pin++) {
pwm.setPWM(pin, 0, 4096);
}
for (uint8_t pin = 1; pin <= 15; pin = pin + 3) {
pwm.setPWM(pin, 0, 3870);
}
for (uint8_t pin = 2; pin <= 15; pin = pin + 3) {
pwm.setPWM(pin, 0, 1060);
}
for (uint8_t pin = 3; pin <= 15; pin = pin + 3) {
pwm.setPWM(pin, 0, 3918);
}
}
if (request.substring(0, 2) == "=" && request.substring(2, 5) == id_device && request.substring(5, 13) == ASI && request.substring(13) == "=") { //HABITACIÓN ASIGNADA (BLANCA NOMENCLATURA)
for (uint8_t pin = 0; pin <= 15; pin++) {
pwm.setPWM(pin, 0, 4096);
}
for (uint8_t pin = 7; pin <= 9; pin++) {
pwm.setPWM(pin, 0, 4095);
}
}
if (request.substring(0, 2) == "=" && request.substring(2, 5) == id_device && request.substring(5, 13) == DNDA && request.substring(13) == "=") { //NO MOLESTAR ASIGNADA (ROJO DND + BLANCA NOMENCLATURA)
for (uint8_t pin = 0; pin <= 15; pin++) {
pwm.setPWM(pin, 0, 4096);
}
pwm.setPWM(15, 0, 4095);
for (uint8_t pin = 7; pin <= 9; pin++) {
pwm.setPWM(pin, 0, 4095);
}
}
if (request.substring(0, 2) == "=" && request.substring(2, 5) == id_device && request.substring(5, 13) == ASEA && request.substring(13) == "=") { //REQUIERE ASEO ASIGNADA (VERDE ASEO + BLANCA NOMENCLATURA)
for (uint8_t pin = 0; pin <= 15; pin++) {
pwm.setPWM(pin, 0, 4096);
}
pwm.setPWM(5, 0, 4095);
for (uint8_t pin = 7; pin <= 9; pin++) {
pwm.setPWM(pin, 0, 4095);
}
}
if (request.substring(0, 2) == "=" && request.substring(2, 5) == id_device && request.substring(5, 13) == ROOA && request.substring(13) == "=") { //REQUIERE ROOM SERVICE ASIGNADA (AZUL ROOM + BLANCA NOMENCLATURA)
for (uint8_t pin = 0; pin <= 15; pin++) {
pwm.setPWM(pin, 0, 4096);
}
pwm.setPWM(10, 0, 4095);
for (uint8_t pin = 7; pin <= 9; pin++) {
pwm.setPWM(pin, 0, 4095);
}
}
if (request.substring(0, 2) == "=" && request.substring(2, 5) == id_device && request.substring(5, 13) == CAMA && request.substring(13) == "=") { //EN CAMARERIA ASIGNADA (AMARILLO CAMARERIA + BLANCA NOMENCLATURA)
for (uint8_t pin = 0; pin <= 15; pin++) {
pwm.setPWM(3, 0, 4000);
pwm.setPWM(2, 0, 2000);
pwm.setPWM(9, 0, 4095);
// pwm.setPWM(10, 0, 4095);
}
}
if (request.substring(0, 2) == "=" && request.substring(2, 5) == id_device && request.substring(5, 13) == ASRA && request.substring(13) == "=") { //REQUIERE ASEO PRIORITARIO ASIGNADA (ROJO ASEO + BLANCA NOMENCLATURA)
for (uint8_t pin = 0; pin <= 15; pin++) {
pwm.setPWM(pin, 0, 4096);
}
pwm.setPWM(6, 0, 4095);
for (uint8_t pin = 7; pin <= 9; pin++) {
pwm.setPWM(pin, 0, 4095);
}
for (uint8_t pin = 7; pin <= 9; pin++) {
pwm.setPWM(pin, 0, 4095);
}
}
if (request.substring(0, 2) == "=" && request.substring(2, 5) == id_device && request.substring(5, 13) == CADA && request.substring(13) == "=") { //CAMARERA DEMORADA ASIGNADA (ROJO CAMARERÍA + BALNCA NOMENCLATURA)
for (uint8_t pin = 0; pin <= 15; pin++) {
pwm.setPWM(pin, 0, 4096);
}
pwm.setPWM(3, 0, 4095);
for (uint8_t pin = 7; pin <= 9; pin++) {
pwm.setPWM(pin, 0, 4095);
}
}
if (request.substring(0, 2) == "=" && request.substring(2, 5) == id_device && request.substring(5, 13) == DNDC && request.substring(13) == "=") { //DND CHECK OUT (ROJO DND + VERDE CHECK OUT)
for (uint8_t pin = 0; pin <= 15; pin++) {
pwm.setPWM(pin, 0, 4096);
}
pwm.setPWM(15, 0, 4095);
pwm.setPWM(8, 0, 4095);
}
if (request.substring(0, 2) == "=" && request.substring(2, 5) == id_device && request.substring(5, 13) == ASEC && request.substring(13) == "=") { //CAMARERIA CHECK OUT (VERDE CAMARERÍA + VERDE NOMENCLATURA)
for (uint8_t pin = 0; pin <= 15; pin++) {
pwm.setPWM(pin, 0, 4096);
}
pwm.setPWM(5, 0, 4095);
pwm.setPWM(8, 0, 4095);
}
if (request.substring(0, 2) == "=" && request.substring(2, 5) == id_device && request.substring(5, 13) == ROOC && request.substring(13) == "=") { //ROOM SERVICE CHECK OUT (AZUL ROOM SEVICE + VERDE NOMENCLATURA)
for (uint8_t pin = 0; pin <= 15; pin++) {
pwm.setPWM(pin, 0, 4096);
}
pwm.setPWM(10, 0, 4095);
pwm.setPWM(8, 0, 4095);
}
if (request.substring(0, 2) == "=" && request.substring(2, 5) == id_device && request.substring(5, 13) == CAMC && request.substring(13) == "=") { //CAMARERIA CHECK OUT (CAMARERIA AMARILLO + VERDE NOMENCLATURA)
for (uint8_t pin = 0; pin <= 15; pin++) {
pwm.setPWM(pin, 0, 4096);
}
pwm.setPWM(3, 0, 4000);
pwm.setPWM(2, 0, 2000);
pwm.setPWM(8, 0, 4095);
}
if (request.substring(0, 2) == "=" && request.substring(2, 5) == id_device && request.substring(5, 13) == CADC && request.substring(13) == "=") { //CAMARERIA CHECK OUT (CAMARERIA AMARILLO + VERDE NOMENCLATURA)
for (uint8_t pin = 0; pin <= 15; pin++) {
pwm.setPWM(pin, 0, 4096);
}
pwm.setPWM(6, 0, 4095);
pwm.setPWM(8, 0, 4095);
}

if (request.substring(0, 2) == "=" && request.substring(2, 10) == "Consulta" && request.substring(10) == "=") {
client.println(request);
}

// WiFiClient cliente; // Se crea el cliente para conectar al host y enviar datos
// const int Port = 49160; // Puerto definido
// if (!cliente.connect(host, Port)) { // Loop hasta que se conecte al host
// Serial.println("connection failed");
// return;
// }

respuesta += "." + id_device + pedido + "." ;
Serial.println(respuesta);
// cliente.println(respuesta);

delay(1);
Serial.println("Recibido");
Serial.println("");
}

Moderador:
Bienvenido al Foro Arduino en Español.
Por favor, lee las Normas del foro y edita tu código usando etiquetas de código.
Ve a edición, luego selecciona todo el error que has publicado, lo cortas y click en </>