so im trying to get the modified version I made of the Bridge example to be able to work with multiple LEDs currently its set up so it works with one LED and turns that LED into a PWM
this is the original code
#include <Bridge.h>
#include <BridgeServer.h>
#include <BridgeClient.h>
BridgeServer server;
void setup() {
Bridge.begin();
server.listenOnLocalhost();
server.begin();
}
void loop() {
BridgeClient client = server.accept();
if (client) {
process(client);
Console.println("client connected and will now close");
client.stop();
}
delay(50);
}
void process(BridgeClient client) {
String command = client.readStringUntil('/');
if (command == "analog") {
analogCommand(client);
}
}
void analogCommand(BridgeClient client) {
int pin, value;
pin = client.parseInt();
if (client.read() == '/') {
value = client.parseInt();
float P = 50; // period of the pulse (dont go below 50)
float DC = {value/255.00}; // duty cycle
while(0 < value){
analogWrite(pin, 255);
delay(P*DC);
analogWrite(pin, 0);
delay(P*(1-DC));
//LOOKING FOR a new client
BridgeClient client = server.accept();
if (client) {
process(client);
Console.println("client connected and will now close");
client.stop();
}
// Send feedback to client
client.print(F("Pin D"));
client.print(pin);
client.print(F(" set to analog "));
client.print(value);
client.print("\t");
client.println(DC);
}
String key = "D";
key += pin;
Bridge.put(key, String(value));
}
}
and this is the code I was trying to use to make the LEDs work separately I thought using the TELE variable to dedicate a pin number would let me dedicate certain pins to certain LED's but it doesn't turn the LEDs on like is should
#include <Bridge.h>
#include <BridgeServer.h>
#include <BridgeClient.h>
BridgeServer server;
void setup() {
Bridge.begin();
server.listenOnLocalhost();
server.begin();
}
void loop() {
BridgeClient client = server.accept();
if (client) {
process(client);
Console.println("client connected and will now close");
client.stop();
}
delay(50);
}
void process(BridgeClient client) {
String command = client.readStringUntil('/');
if (command == "analog") {
analogCommand(client);
}
}
void analogCommand(BridgeClient client) {
int value, tele;
if (client.read() == '/') {
value = client.parseInt();
if (client.read() == '/') {
tele = client.parseInt();
if (tele == 1){
int pin = 5;
float P = 50; // period of the pulse (dont go below 50)
float DC = {value/255.00}; // duty cycle
while(0 < value){
analogWrite(pin, 255);
delay(P*DC);
analogWrite(pin, 0);
delay(P*(1-DC));
//LOOKING FOR a new client
BridgeClient client = server.accept();
if (client) {
process(client);
Console.println("client connected and will now close");
client.stop();
}
// Send feedback to client
}
if (tele == 2){
int pin = 6;
float P = 50; // period of the pulse (dont go below 50)
float DC = {value/255.00}; // duty cycle
while(0 < value){
analogWrite(pin, 255);
delay(P*DC);
analogWrite(pin, 0);
delay(P*(1-DC));
//LOOKING FOR a new client
BridgeClient client = server.accept();
if (client) {
process(client);
Console.println("client connected and will now close");
client.stop();
}
}
}client.print(F("Pin D"));
client.print(pin);
client.print(F(" set to analog "));
client.print(value);
client.print("\t");
client.println(DC);
}
String key = "D";
//key += pin;
Bridge.put(key, String(value));
}
}
}