Is there any way to separate this short code into its own function? (webserver, trying to use client.print outside of main loop) 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("&lt;HTML&gt;&lt;HEAD&gt;"));
...
if (fan1Toggle == 0)
    client.print(F("Fan1&lt;font color=\"red\"&gt;&amp;#8226;&lt;/font&gt;&lt;a href=\"/?fan1on\"&gt;On&lt;/a&gt;&lt;br&gt;"));
else
    client.print(F("Fan1&lt;font color=\"green\"&gt;&amp;#8226;&lt;/font&gt;&lt;a href=\"/?fan1off\"&gt;Off&lt;/a&gt;&lt;br&gt;"));

if (fan2Toggle == 0)
    client.print(F("Fan2&lt;font color=\"red\"&gt;&amp;#8226;&lt;/font&gt;&lt;a href=\"/?fan2on\"&gt;On&lt;/a&gt;&lt;br&gt;"));
else
    client.print(F("Fan2&lt;font color=\"green\"&gt;&amp;#8226;&lt;/font&gt;&lt;a href=\"/?fan2off\"&gt;Off&lt;/a&gt;&lt;br&gt;"));
...


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 ("&amp;#8226", like &#8226;) 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("&lt;font color=\"red\"&gt;&amp;#8226;&lt;/font&gt;"));
else    //switch is on, so display green bullet
    client.print(F("&lt;font color=\"green\"&gt;&amp;#8226;&lt;/font&gt;"));
}


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!
You can pass client to the function by reference, like this:

void displayBullet(EthernetClient &amp; client, int toggle) 
  {
  if (toggle == 0)     //switch is off, so display red bullet
    client.print(F("&lt;font color=\"red\"&gt;&amp;#8226;&lt;/font&gt;"));
  else    //switch is on, so display green bullet
    client.print(F("&lt;font color=\"green\"&gt;&amp;#8226;&lt;/font&gt;"));
  }


Now it knows about client. Make sure you pass client when you call it:

displayBullet(client, 1);