I have an arduino webserver that uses the following code:
client.println(F("HTTP/1.1 200 OK"));
client.println(F("Content-Type: text/html"));
client.println();
client.println(F("<HTML><HEAD>"));
...
if (fan1Toggle == 0)
client.print(F("Fan1<font color=\"red\">•</font><a href=\"/?fan1on\">On</a><br>"));
else
client.print(F("Fan1<font color=\"green\">•</font><a href=\"/?fan1off\">Off</a><br>"));
if (fan2Toggle == 0)
client.print(F("Fan2<font color=\"red\">•</font><a href=\"/?fan2on\">On</a><br>"));
else
client.print(F("Fan2<font color=\"green\">•</font><a href=\"/?fan2off\">Off</a><br>"));
...
The page is pretty long, allowing the user to toggle over a dozen different switches. Some of the code checks to see the state of a certain switch, and then displays a green or red bullet ("•", like •) on the page if the switch is on or off.
Since the code for the colored bullet is repeating, I wanted to make a function for it. Then I would just call (for example) "displayBullet(fan1Toggle);
", and it would determine if fan1 was on or off, and display the correct color depending on the state.
I tried to create the following function:
void displayBullet(int toggle) {
if (toggle == 0) //switch is off, so display red bullet
client.print(F("<font color=\"red\">•</font>"));
else //switch is on, so display green bullet
client.print(F("<font color=\"green\">•</font>"));
}
But then I got an error saying that "'client' is not declared in this scope".
Is there any way to work around that error, so that I can get the displayBullet() function I want? Or is this something that can't be shortened like this, because the "client" function has to be inside the main loop?
Thanks!