Hi guys. I want to make my code a bit more robust and light because I have a little bit of trouble with the amount of data the ethernet shield can handle. If I am near 16kb of code, it crashes, although the arduino has 32kb. Anyway... To the point
I want to substitute the following piece of code and make a "for loop" for the pins 2-9 but I don't know how to make it read the ("on1"), ("off1), with 1 being an int i.
if(readString.indexOf("on1") >0)//checks for on
{
digitalWrite(2, HIGH); // set pin 2 high
// Serial.println("Led On");
//client.println("Light 1 Is On");
//client.println("
");
}
else{
if(readString.indexOf("off1") >0)//checks for off
{
digitalWrite(2, LOW); // set pin 2 low
// Serial.println("Led Off");
//client.println("Light 1 Is Off");
//client.println("
");
}
}if(readString.indexOf("on2") >0)//checks for on
{
digitalWrite(3, HIGH); // set pin 3 high
// Serial.println("Led On");
}
else{
if(readString.indexOf("off2") >0)//checks for off
{
digitalWrite(3, LOW); // set pin 3 low
// Serial.println("Led Off");
}
}
I want it to be something like but obviously doesn't work because its wrong syntax.
for (int i=1; i<9;i++)
if(readString.indexOf("on"i) >0)//checks for on
{
digitalWrite(i+1, HIGH); // set pin i+1 high
}
else{
if(readString.indexOf("off"i) >0)//checks for off
{
digitalWrite(i+1, LOW); // set pin i+1 low
}
}
}