 void PIRCHECKING()
 {
   pirOnOff = digitalRead(PIR_IN_PIN);
-}
-
-
-void tvOnTimer() 
-{
-    t.stop(tvIsOffEvent);
-    tvIsOnEvent = t.every(3000000, doTvOnOffbyTimer("off"));
+  Serial.println("PIR rising called");
+}
+
+
+void tvOnTimer()
+{
+  t.stop(tvIsOffEvent);
+  tvIsOnEvent = t.every(3000000, doTvOffTimer);
 }
 
 void tvOffTimer()
 {
-    t.stop(tvIsOnEvent);
-    tvIsOffEvent = t.every(600000, doTvOnOffbyTimer("on"));
-}
-
-void doTvOnOffbyTimer(String onoff)
+  t.stop(tvIsOnEvent);
+  tvIsOffEvent = t.every(600000, doTvOnTimer);
+}
+
+void doTvOffTimer()
+{
+  irSendTv(0);
+  tvOffTimer();
+  lcd.setCursor(15, 0);
+  lcd.write(6);
+}
+
+void doTvOnTimer()
+{
+  irSendTv(1);
+  tvOnTimer();
+  lcd.setCursor(15, 0);
+  lcd.print(" ");
+}
+
+
+
+void doTvControlbyPir(int onoff)
 {
   switch (onoff) {
-    case on:
-      irSendTv("on");
-      tvOnTimer();
+    case 1:
       lcd.setCursor(15, 0);
-      lcd.print(" ");      
+      lcd.print(" ");
+      irSendTv(1);
       break;
-    case off:
-      irSendTv("off");
-      tvOffTimer();
+    case 0:
       lcd.setCursor(15, 0);
-      lcd.write(6);      
+      lcd.write(6);
+      irSendTv(0);
       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 ) 
+  r = !r;
+}
+
+void irSendTv(int onoff)
+{
+  if ( o_wrkMode == 1 && o_startMode == 1 )
   {
-    if ( offMode == 1 ) 
+    if ( o_offMode == 1 )
     {
-        switch (onoff) {
-          case on:
-            if ( tvPowerStatus == 0 ) 
-            {
-                  irsend.sendNEC(tv_onoff, 32);
-                  tvPowerStatus = 1;
-                  temp_Mills = millis();
-                  delay(300);
-                  irrecv.enableIRIn();            
+      switch (onoff) {
+        case 1:
+          if ( tvPowerStatus == 0 )
+          {
+            irsend.sendNEC(tv_onoff, 32);
+            tvPowerStatus = 1;
+            temp_Mills = millis();
+            delay(300);
+            irrecv.enableIRIn();
+          }
+          break;
+        case 0:
+          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 1:
+          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);
             }
-            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();                            
+            irsend.sendNEC(tv_enter, 32);
+            tvPowerStatus = 1;
+            delay(300);
+            irrecv.enableIRIn();
+          }
+          break;
+        case 0:
+          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);
             }
-            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; 
-        }
-
+            irsend.sendNEC(tv_enter, 32);
+            tvPowerStatus = 0;
+            delay(300);
+            irrecv.enableIRIn();
+          }
+          break;
+        default:
+          return;
+          break;
+      }
     }
   } else {
- 
+
     return;
- 
-  }
- 
+
+  }
+
 }
 
 // TimeTime
 void displaytimeleft() {
-
+  float timeleft;
   if ( tvPowerStatus == 1) {
-    float timeleft = o_tvOnTime - ((millis() - temp_Mills) / 1000 / 60) ;
+    timeleft = o_tvOnTime - ((millis() - temp_Mills) / 1000 / 60) ;
   } else {
-    float timeleft = o_tvOffTime - ((millis() - temp_Mills) / 1000 / 60) ;
+    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);
+  if ( timerStatus == 1 &&  o_wrkMode == 1 && o_startMode == 1 ) {
+    for ( int i = 0; i < ( 3 - length_a ) ; i++ ) {
+      lcd.print(" ");
+    }
+    lcd.print(str_a);
+  } else {
+    lcd.print("   ");
+  }
 
 }
 

  /*
  int updateTempCArrayEvent = t.every(300000, doUpdateTempCArray);
  */
 
  // PIR
  attachInterrupt(0, PIRCHECKING, CHANGE);

}


  pinMode(WRK_MODE_IN_PIN, INPUT);
  // SETUP_IN_PIN and WRK_MODE_IN_PIN is analog pin, to pull-up
  digitalWrite(SETUP_IN_PIN, HIGH);
  digitalWrite(WRK_MODE_IN_PIN, HIGH);

  pinMode(PIR_IN_PIN, INPUT);

  // buzzer
  pinMode(BZ_OU_PIN, OUTPUT);
  digitalWrite(BZ_OU_PIN, HIGH);

  delay(300);

  // PIR
  attachInterrupt(0, PIRCHECKING, CHANGE);

  // read pin status
  setUpStatus   = digitalRead(SETUP_IN_PIN);
