 //how many clients should be able to telnet to this ESP8266
 #define MAX_SRV_CLIENTS 1
 #define PORT 8081
+#define MAX_PWM_VAL 5
 
 const char* ssid     = "***************";
 const char* password = "***************";
-
-// how much serial data we expect before a newline
-const unsigned int MAX_INPUT = 1024;
+// WIFI
+const unsigned int MAX_INPUT = 1024; // how much serial data we expect before a newline
 
 WiFiServer server(PORT);
 WiFiClient serverClients[MAX_SRV_CLIENTS];
 
+// State-machine
+typedef enum {  NONE, LED, DELAY } states; // the possible states of the state-machine
+states state = NONE;                                // current state-machine state
+unsigned int currentValue = 0;                          // current partial number
+unsigned int currentLed = 0;
+const unsigned int ledCount = 4;
+const unsigned int leds[] = {12, 13, 14, 15};
+
 void setup() {
   // Initializing the used pins
-  // pinMode(0, OUTPUT);  // Red led on the ESP, might be used later for debugging
-  pinMode(12, OUTPUT);
-  pinMode(13, OUTPUT);
-  pinMode(14, OUTPUT);
-  pinMode(15, OUTPUT);
+  int i;
+  for (i = 0; i < ledCount; i++) {
+    pinMode(leds[i], OUTPUT);
+  }
+  analogWriteRange(MAX_PWM_VAL);
 
   Serial.begin(115200);
   delay(100);

}

// here to process incoming serial data after a terminator received
void process_data (const char * data)
{
  Serial.println (data);
  blink();
}

void blink() {
  digitalWrite(12, HIGH);
  delay(50);
  digitalWrite(12, LOW);
  delay(50);
  digitalWrite(13, HIGH);
  delay(50);
  digitalWrite(13, LOW);
  delay(50);
  digitalWrite(14, HIGH);
  delay(50);
  digitalWrite(14, LOW);
  delay(50);
  digitalWrite(15, HIGH);
  delay(50);
  digitalWrite(15, LOW);
  delay(50);
}


  }
}

void processIncomingByte (const byte inByte) {
  static char input_line [MAX_INPUT];
  static unsigned int input_pos = 0;

  switch (inByte) {
    case '\n':   // end of text
      input_line [input_pos] = 0;  // terminating null byte
      process_data (input_line);   // terminator reached! process input_line here ...
      input_pos = 0;               // reset buffer for next time
      break;
    case '\r':   // discard carriage return
      break;
