Hi Paul.
Thanks for the input. That makes sense, so each time the arduino asks the controller if it has x y z string waiting for it?
so, I want to check for the animation string from the ethernet controller, then run the animation loop until another string arrives - which I have to check for.
I'm using 'if' statements to check for certain strings, and they will only be true once then the string will be gone, so how could I make the 'if' loop run continuously and check for other strings without running the rest of the loop() function running?
I hope that makes sense, maybe I am being daft and over complicating this matter?
The main code is below, currently if you go into the stars() function it appears to run only twice, but I can't see where the flag is being set back to false? - I'm sure there must be a less clunky way of doing this without messing around with flags?
//////////////////////
//INCLUDES
//////////////////////
#include <SPI.h>
#include <Ethernet.h>
#include "Tlc5940.h"
//////////////////////
//END OF INCLUDES
//////////////////////
//////////////////////
//DEFINES
//////////////////////
int TLCDelay = 50;Â //Delay after setting TLC
int brightness = 4095;Â //Initial brightness to display
int dimStep = 0;
boolean flag = false;Â //flag for animation or single shot, false = single shot
int pinNumber = 0;
// number of items in an array
#define NUMITEMS(arg) ((unsigned int) (sizeof (arg) / sizeof (arg [0])))
//int vals [] = { 1000, 1000, 500, 500, 250, 200, 175, 175, 100, 75, 40, 5};
int vals [] = {
 2047, 1024, 512, 256, 128, 64, 16, 16, 32 };
int numVal = NUMITEMS (vals); //number of values in array
//////////////////////
//END OF DEFINES
//////////////////////
//////////////////////
//ETHERNET SETUP
//////////////////////
byte mac[] = {
 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = {
 192, 168, 0, 177 }; // ip in lan
byte gateway[] = {
 192, 168, 1, 1 }; // internet access via router
byte subnet[] = {
 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
String readString;
//////////////////////
//END OF ETHERNET SETUP
//////////////////////
//////////////////////
//START OF MODES
//////////////////////
void allOn(){
 Tlc.clear();
 digitalWrite(7, HIGH);
 Tlc.setAll(brightness);
 Tlc.update();
 delay(TLCDelay);
}
void sides(){
 Tlc.clear();
 digitalWrite(7, HIGH);
 for (int i = 0; i < 4; i++)
 {
  Tlc.set(i, brightness);
 }
 for (int i = 7; i < 11; i++)
 {
  Tlc.set(i, brightness);
 }
 Tlc.update();
 delay(TLCDelay);
}
void gradient(){
 Tlc.clear();
 for (int i = 0; i < 4; i++)
  Tlc.set(i, 4095);
 for (int i = 4; i < 8; i++)
  Tlc.set(i, 1000);
 for (int i = 8; i < 12; i++)
  Tlc.set(i, 250);
 for (int i = 12; i < 16; i++)
  Tlc.set(i, 100);
 Tlc.update();
 delay(TLCDelay);
}
void frontRow(){
 Tlc.clear();
 Tlc.set(0, brightness);
 Tlc.set(4, brightness);
 Tlc.set(7, brightness);
 Tlc.update();
 delay(TLCDelay);
}
void middle(){
 Tlc.clear();
 Tlc.set(4, brightness);
 Tlc.set(5, brightness);
 Tlc.set(6, brightness);
 Tlc.update();
 delay(TLCDelay);
}
void alternate(){
 Tlc.clear();
 Tlc.set(0, brightness);
 Tlc.set(2, brightness);
 Tlc.set(5, brightness);
 Tlc.set(7, brightness);
 Tlc.set(9, brightness);
 Tlc.update();
 delay(TLCDelay);
}
void stars(){
 Tlc.clear();
 Tlc.set(pinNumber, brightness);
 Tlc.update();
 pinNumber++;
 delay(100);
 delay(TLCDelay);
 flag = true;
}
//////////////////////
//END OF MODES
//////////////////////
//////////////////////
//START OF DIMMING CONTROL
//////////////////////
void up(){
 if ((brightness + vals[dimStep]) < 4095)
 {
  brightness = (brightness + vals[(dimStep - 1)]) ; //set new brightness level
  dimStep--;
 }
 Serial.println(brightness);
 Tlc.setAll(brightness);
 Tlc.update();
 delay(TLCDelay);
}
void down(){
 if (dimStep < numVal)
 {
  brightness = (brightness - vals[dimStep]); //set new brightness level
  dimStep++;
 }
 Serial.println(brightness);
 Tlc.setAll(brightness);
 Tlc.update();
 delay(TLCDelay);
}
//////////////////////
//END OF DIMMING CONTROL
//////////////////////
void setup(){
 Tlc.init(0);
 pinMode(7, OUTPUT); //pin selected to control
 //start Ethernet
 Ethernet.begin(mac, ip, gateway, subnet);
 server.begin();
 Serial.begin(9600);
}
void loop(){
 // Create a client connection
 EthernetClient client = server.available();
 if (client) {
  while (client.connected()) {
   if (client.available()) {
    char c = client.read();
    //read char by char HTTP request
    if (readString.length() < 100) {
     //store characters to string
     readString += c;
     //Serial.print(c);
    }
    //if HTTP request has ended
    if (c == '\n') {
     ///////////////
     client.println("HTTP/1.1 200 OK"); //send new page
     client.println("Content-Type: text/html");
     client.println();
     client.println("<HTML>");
     client.println("<HEAD>");
     client.println("<meta name='apple-mobile-web-app-capable' content='yes' />");
     client.println("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />");
     client.println("<link rel='stylesheet' type='text/css' href='https://dl.dropbox.com/u/33809233/a.css' />");
     client.println("<TITLE>Home Automation</TITLE>");
     client.println("<meta name=\"viewport\" content=\"user-scalable = yes\" />"); //?
     client.println("<meta name=\"viewport\" content=\"width=device-width, height=device-height, initial-scale=1, maximum-scale=1\" />");
     client.println("</HEAD>");
     client.println("<BODY>");
     client.println("<H1>Home Automation</H1>");
     client.println("<hr />");
     client.println("
");
     client.println("<a href=\"/?lighton\"\">All On</a>");
     client.println("<a href=\"/?lightoff\"\">All Off</a>
");
     client.println("
");
     client.println("<hr />");
     client.println("
");
     client.println("<a href=\"/?up\"\">Up</a>");
     client.println("<a href=\"/?down\"\">Down</a>
");
     client.println("
");
     client.println("<hr />");
     client.println("
");
     client.println("<a href=\"/?sides\"\">Sides</a>");Â
     client.println("<a href=\"/?gradient\"\">Gradient</a>
");
     client.println("
");
     client.println("
");
     client.println("<a href=\"/?frontRow\"\">Front Row</a>");
     client.println("<a href=\"/?alternate\"\">Alternate</a>");
     client.println("<a href=\"/?middle\"\">Middle</a>
");
     client.println("
");
     client.println("<hr />");
     client.println("
");
     client.println("<a href=\"/?stars\"\">Stars</a>
");
     client.println("</BODY>");
     client.println("</HTML>");
     delay(1);
     //stopping client
     client.stop();
   Â
     if(readString.indexOf("?lighton") >0)
     {
      allOn();
      flag = false;
     }
     else if(readString.indexOf("?lightoff") >0)
     {
      Tlc.setAll(0);
      Tlc.update();
      delay(TLCDelay);
      flag = false;
     }
     else if(readString.indexOf("?sides") >0)
     {
      sides();
      flag = false;
     }
     else if(readString.indexOf("?gradient") >0)
     {
      gradient();
      flag = false;
     }
     else if(readString.indexOf("?up") >0)
     {
      up();
     }
     else if(readString.indexOf("?down") >0)
     {
      down();
     }
     else if(readString.indexOf("?frontRow") >0)
     {
      frontRow();
      flag = false;
     }
     else if(readString.indexOf("?middle") >0)
     {
      middle();
      flag = false;
     }
     else if(readString.indexOf("?alternate") >0)
     {
      alternate();
      flag = false;
     }
     else if(readString.indexOf("?stars") >0 || flag == true)
     {
      stars();
     }
     //clearing string for next read
     readString="";
    }
   }
  }
 }
}
/*
      digitalWrite(7, LOW);
//Tlc.set(1, 0);
//Tlc.set(15, 0);
for (int i = 4095; i > (0-1) ; i--)
{
Tlc.set(15, i);
Tlc.set(10, i);
Tlc.update();
delay(1);
}
Tlc.set(9, 0);
Tlc.update();
delay(100);
*/