Hello,
I am trying to control LEDs via telnet.
All what i want to do is send "11111" to arduino to turn on the 5 LEDs or send "11000" to turn on the first two and turn off the rest.
Any command i send it turns all on and can't turn them off.
Here's my code
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10,0,0,151 };
Server server(23);
int pinArray[] = {2, 3, 4, 5, 6};
int Max = 4;
String readString;
boolean Comm = LOW;
void setup() {
// initialize the ethernet device
Ethernet.begin(mac, ip);
// start listening for clients
server.begin();
// open the serial port for logging
Serial.begin(9600);
for (int count=0;count<5;count++) {
pinMode(pinArray[count], OUTPUT);
}
}
void loop()
{
Client client = server.available();
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (readString.length() < Max + 1) {
//store characters to string
readString += c;
}
// command complete
if (c == '\n') {
//Serial.println(readString);
for (int i=0; i <= Max; i++){
Serial.println (readString[i]);
if (readString[i] == "0"){
Comm = LOW;
}else{
Comm = HIGH;
}
digitalWrite(pinArray[i],Comm);
}
readString = "";
}
}
}
}
What is wrong with my code ?
Also.. is there any recommendations for my code or modifications make it better ?
Thanks all in advanced.