   lcd.backlight();
   lcd.clear();
 
-  // when connected to usb of TV...
-  delay(10000);
+  delay(5000);
 
   // Timer start
   temp_Mills = millis();

void PIRCHECKING()
{
  pirOnOff = digitalRead(PIR_IN_PIN);
}


void tvOnTimer() 
{
    t.stop(tvIsOffEvent);
    tvIsOnEvent = t.every(3000000, doTvOnOffbyTimer("off"));
}

void tvOffTimer()
{
    t.stop(tvIsOnEvent);
    tvIsOffEvent = t.every(600000, doTvOnOffbyTimer("on"));
}

void doTvOnOffbyTimer(String onoff)
{
  switch (onoff) {
    case on:
      irSendTv("on");
      tvOnTimer();
      lcd.setCursor(15, 0);
      lcd.print(" ");      
      break;
    case off:
      irSendTv("off");
      tvOffTimer();
      lcd.setCursor(15, 0);
      lcd.write(6);      
      break;
  }
}

void doTvControlbyPir(String onoff)
{
  switch (onoff) {
    case on:
      irSendTv("on");
      break;
    case off:
      irSendTv("off");
      break;
  }
}

void irSendTv(String onoff)
{
  if ( wrkMode == 1 && startMode == 1 ) 
  {
    if ( offMode == 1 ) 
    {
        switch (onoff) {
          case on:
            if ( tvPowerStatus == 0 ) 
            {
                  irsend.sendNEC(tv_onoff, 32);
                  tvPowerStatus = 1;
                  temp_Mills = millis();
                  delay(300);
                  irrecv.enableIRIn();            
            }
            break;
          case off:
            if ( tvPowerStatus == 1 ) 
            {
                  irsend.sendNEC(tv_onoff, 32);
                  tvPowerStatus = 0;
                  temp_Mills = millis();
                  delay(300);
                  irrecv.enableIRIn();            
            }          
            break;
          default:
            return;
            break;
        }  
    } else {
        switch (onoff) {
          case on:
            if ( tvPowerStatus == 0 ) 
            {
                  irsend.sendNEC(tv_input, 32);
                  delay(3000);
                  for ( int i = 0 ; i < o_channelGap ; i++ ) {
                    irsend.sendNEC(tv_left, 32);
                    delay(300);
                  }
                  irsend.sendNEC(tv_enter, 32);
                  tvPowerStatus = 1;
                  delay(300);
                  irrecv.enableIRIn();                            
            }
            break;
          case off:
            if ( tvPowerStatus == 1 ) 
            {
                  irsend.sendNEC(tv_input, 32);
                  delay(3000);
                  for ( int i = 0 ; i < o_channelGap ; i++ ) {
                    irsend.sendNEC(tv_right, 32);
                    delay(300);
                  }
                  irsend.sendNEC(tv_enter, 32);
                  tvPowerStatus = 0;
                  delay(300);
                  irrecv.enableIRIn();     
            }          
            break;
          default:
            return;
            break; 
        }

    }
  } else {
 
    return;
 
  }
 
}

// TimeTime
void displaytimeleft() {

  if ( tvPowerStatus == 1) {
    float timeleft = o_tvOnTime - ((millis() - temp_Mills) / 1000 / 60) ;
  } else {
    float timeleft = o_tvOffTime - ((millis() - temp_Mills) / 1000 / 60) ;
  }

  String str_a = String(int(timeleft));
  int length_a = str_a.length();

  lcd.setCursor(10, 1);
  for ( int i = 0; i < ( 3 - length_a ) ; i++ ) {
    lcd.print(" ");
  }
  lcd.print(str_a);

}


    lcd.print(abs(tempdiff), 1);
    if ( length_tempdiff == 1) {
      lcd.print(" ");
    }
  }
}

