   th_Val[5].bits[2] = 1;
   th_Val[6].bits[0] = 0; //values for GB
   th_Val[6].bits[1] = 1;
-  th_Val[6].bits[2] = 1; 
+  th_Val[6].bits[2] = 1;
   th_Val[7].bits[0] = 1; //values for RGB
   th_Val[7].bits[1] = 1;
   th_Val[7].bits[2] = 1;

  Serial.print(sync);
  Serial.println(" to send threshold sequence");
  uint16_t r_h, g_h, b_h;
  setupMain: //come back here untill sync seq start
  if (Serial.available() > 0) //if there is an input data
  {
    inputHOLD = Serial.readString(); //get input

    if(inputHOLD == sync) //check for sync code
      {
        synchronization(); //if true sync
        goto setupMain; //then go back
       }
  }
  tcs.getRawData(&r, &g, &b, &c); //get env info
  //R00
  if(r < th_Val[0].r_t) //go back if red is lower then OFF threshold
  {
    goto setupMain;
  }

    }
    else
    {
      th_Val[3].r_t = ((float) r_h * thErrOFF);
      th_Val[3].g_t = ((float) g_h * thErrOFF);
      th_Val[3].b_t = ((float) b_h * thErrON);
      break;
    }
  }
  while (b > th_Val[0].b_t)
  {
    tcs.getRawData(&r, &g, &b, &c); //wait until blue is LOW
  }
  Serial.print(".");
  //RG0
  while ((r < th_Val[0].r_t) | (g < th_Val[0].g_t)) //wait until red and green is HIGH
  {
    tcs.getRawData(&r, &g, &b, &c);
  }
  delay(setupWaitTime);
  //set threshold for red-green high
  r_h = g_h = b_h = 0;
  while (true)
  {
    tcs.getRawData(&r, &g, &b, &c); //get env info
    if (r > r_h)
    {
      r_h = r;
      if (b_h < b)
      {
        b_h = b;
      }
    }
    else if (g > g_h)
    {
      g_h = g;
      if (b_h < b)
      {
        b_h = b;
      }
    }
    else
    {
      th_Val[4].r_t = ((float) r_h * thErrON);
      th_Val[4].g_t = ((float) g_h * thErrON);
      th_Val[4].b_t = ((float) b_h * thErrOFF);
      break;
    }
  }
  while ((r > th_Val[0].r_t) | (g > th_Val[0].g_t)) //wait until red and green is LOW
  {
    tcs.getRawData(&r, &g, &b, &c);
  }
  Serial.print(".");
  //R0B
  while ((r < th_Val[0].r_t) | (b < th_Val[0].b_t)) //wait until red and blue is HIGH
  {
    tcs.getRawData(&r, &g, &b, &c);
  }
  delay(setupWaitTime);
  //set threshold for red-blue high
  r_h = g_h = b_h = 0;
  while (true)
  {
    tcs.getRawData(&r, &g, &b, &c); //get env info
    if (r > r_h)
    {
      r_h = r;
      if (g_h < g)
      {
        g_h = g;
      }
    }
    else if (b > b_h)
    {
      b_h = b;
      if (g_h < g)
      {
        g_h = g;
      }
    }
    else
    {
      th_Val[5].r_t = ((float) r_h * thErrON);
      th_Val[5].g_t = ((float) g_h * thErrOFF);
      th_Val[5].b_t = ((float) b_h * thErrON);
      break;
    }
  }

  while ((r > th_Val[0].r_t) | (b > th_Val[0].b_t)) //wait until red and blue is LOW
  {
    tcs.getRawData(&r, &g, &b, &c);
  }
  Serial.print(".");
  //0GB
  while ((g < th_Val[0].g_t) | (b < th_Val[0].b_t)) //wait until green and blue is HIGH
  {
    tcs.getRawData(&r, &g, &b, &c);
  }
  delay(setupWaitTime);
  //set threshold for green-blue high
  r_h = g_h = b_h = 0;
  while (true)
  {
    tcs.getRawData(&r, &g, &b, &c); //get env info
    if (b > b_h)
    {
      b_h = b;
      if (r_h < r)
      {
        r_h = r;
      }
    }
    else if (g > g_h)
    {
      g_h = g;
      if (r_h < r)
      {
        r_h = r;
      }
    }
    else
    {
      th_Val[6].r_t = ((float) r_h * thErrOFF);
      th_Val[6].g_t = ((float) g_h * thErrON);
      th_Val[6].b_t = ((float) b_h * thErrON);
      break;
    }
  }
  while ((g > th_Val[0].g_t) | (b > th_Val[0].b_t)) //wait until green and blue is LOW
  {
    tcs.getRawData(&r, &g, &b, &c);
  }
  Serial.print(".");
  //RGB
  while ((g < th_Val[0].g_t) | (b < th_Val[0].b_t) | (r < th_Val[0].r_t)) //wait until red, green and blue is HIGH
  {
    tcs.getRawData(&r, &g, &b, &c);
  }
  delay(setupWaitTime);
  //set threshold for red-green-blue high
  r_h = g_h = b_h = 0;
  while (true)
  {
    tcs.getRawData(&r, &g, &b, &c); //get env info
    if (r > r_h)
    {
      r_h = r;
    }
    else if (g > g_h)
    {
      g_h = g;
    }
    else if (b_h < b)
    {
      b_h = b;
    }
    else
    {
      th_Val[7].r_t = ((float) r_h * thErrON);
      th_Val[7].g_t = ((float) g_h * thErrON);
      th_Val[7].b_t = ((float) b_h * thErrON);
      break;
    }
  }

  while ((g > th_Val[0].g_t) | (b > th_Val[0].b_t) | (r > th_Val[0].r_t)) //wait until red, green and blue is HIGH
  {
    tcs.getRawData(&r, &g, &b, &c);
  }
  Serial.println("Done");
  //print env values
  for (int j = 0; j < 8; j++)
  {
    Serial.print("Env ");
    Serial.print(j);
