 Average<float> ave(5);
 
 int power_status = 1 ;
+
+unsigned long  tv_input = 0x20DFD02F;
+unsigned long  tv_right = 0x20DF609F;
+unsigned long  tv_left  = 0x20DFE01F;
+unsigned long  tv_enter = 0x20DF22DD;
+
+int tv_cur_input_no  = 1;
+int tv_move_input_no = 3;
 
 void setup() {
   Serial.begin (38400);

  Serial.println(int(ave.stddev()));

  if ( ( ave.stddev() < 10) && ( int(ave.mean()) <= 60 )  && ( power_status == 1) ) {
    Serial.println("tv off");
    irsend.sendNEC(0x20DF10EF, 32); // LG TV power code
    delay(50);
    power_status = 0;
  }

  if ( ( ave.stddev() < 10) && ( int(ave.mean()) > 100 )  && ( power_status == 0) ) {
    Serial.println("tv on");
    irsend.sendNEC(0x20DF10EF, 32); // LG TV power code
    delay(50);
    power_status = 1;
  }

#include <Average.h>
#include <Ultrasonic.h>
#include <IRremote.h>

IRsend irsend;

Ultrasonic ultraleft(5,6,30000);   // (Trig PIN,Echo PIN)
