/********************************************************
*  Code to use the IR remote control to rotate the TV
*  By: Jonathan Mash
*  Date: Mar. 2009
*********************************************************/
 
#define TIMER_RESET  TCNT1 = 0
#define SAMPLE_SIZE  38
#define DEBUG 0
#define led_pin 4
#define IRpin 2
#define OUTPIN 12                                 //Pulse out to Motor Controller Default 12
#define SETUPPIN 13                               //Pin to hold Motor at 90
 
unsigned int TimerValue[SAMPLE_SIZE];
char direction[SAMPLE_SIZE];
byte change_count;
long time;
bool checkIR;
int curPos = 90;
 
void setup() 
{
  TCCR1A = 0x00;          // COM1A1=0, COM1A0=0 => Disconnect Pin OC1 from Timer/Counter 1 -- PWM11=0,PWM10=0 => PWM Operation disabled
  // ICNC1=0 => Capture Noise Canceler disabled -- ICES1=0 => Input Capture Edge Select (not used) -- CTC1=0 => Clear Timer/Counter 1 on Compare/Match
  // CS12=0 CS11=1 CS10=1 => Set prescaler to clock/64
  TCCR1B = 0x03;          // 16MHz clock with prescaler means TCNT1 increments every 4uS
  // ICIE1=0 => Timer/Counter 1, Input Capture Interrupt Enable -- OCIE1A=0 => Output Compare A Match Interrupt Enable -- OCIE1B=0 => Output Compare B Match Interrupt Enable
  // TOIE1=0 => Timer 1 Overflow Interrupt Enable
  TIMSK1 = 0x00;          
 
  pinMode(IRpin, INPUT);
  pinMode(led_pin, OUTPUT);
  checkIR = false;
  attachInterrupt(0, isrIR, FALLING);
 
  pinMode(OUTPIN, OUTPUT);
  pinMode(SETUPPIN, OUTPUT); 
 
  digitalWrite(SETUPPIN, HIGH);
  delay(10000);
  digitalWrite(SETUPPIN, LOW);
 
 
  Serial.begin(9600);
}
 
void isrIR()
{
  checkIR = true; 
}
 
 
 
void loop()
{
   if(checkIR == true)
   {    
     int retVal = getIR();
     checkIR = false;
 
     switch(retVal)
     {  
       case 384: //Volume up
         if(DEBUG) Serial.println("Volume Up");       
         break;
       case 64: //Volume down
         if(DEBUG) Serial.println("Volume Down");
         break;
       case 224: //Power
         if(DEBUG) Serial.println("Power");
         break;
       case 48: //Left
         if(DEBUG) Serial.println("Left");
         curPos = curPos + 5;
         if(curPos > 180)
           curPos = 180;
         else if(curPos < 0)
           curPos = 0;
         moveTV(curPos);
         break;
       case 50: //Right
         if(DEBUG) Serial.println("Right");
         curPos = curPos - 5;
         if(curPos > 180)
           curPos = 180;
         else if(curPos < 0)
           curPos = 0;
         moveTV(curPos);
         break;
 
     }
   }
}
 
void moveTV(int pos) {
  float newPos = pos;
  int inDelays = (int)floor(1300.0 + (400.0*newPos/180.0));
 
  digitalWrite(OUTPIN, HIGH);
  delayMicroseconds(inDelays);
  digitalWrite(OUTPIN, LOW);
}
 
 
int getIR()
{
  int value = 0;
 
  //Capture Signal
  change_count = 0;
  while(digitalRead(IRpin) == HIGH) {}                                 
  TIMER_RESET;
  TimerValue[change_count] = TCNT1;
  direction[change_count++] = '0';
  while (change_count < SAMPLE_SIZE) {
    if (direction[change_count-1] == '0') {
      while(digitalRead(IRpin) == LOW) {}
      TimerValue[change_count] = TCNT1;
      direction[change_count++] = '1';
    } else {
      while(digitalRead(IRpin) == HIGH) {}
      TimerValue[change_count] = TCNT1;
      direction[change_count++] = '0';
    }
  }
 
  //Analyze Signal
  change_count = 0;
  time = (long) TimerValue[change_count] * 4;
  change_count++;
  while (change_count < SAMPLE_SIZE) {
    time = (long) TimerValue[change_count] * 4;
    if(direction[change_count-1] == '0' && direction[change_count] == '1')
    {
      //Do nothing
    }
    else if(direction[change_count-1] == '1' && direction[change_count] == '0')
    {
      if(time - (long)TimerValue[change_count-1] * 4 > 2000)
      {
        if(DEBUG) Serial.print("-");
        value = 0;
      }
      else if(time - (long)TimerValue[change_count-1] * 4 > 1000)
      {
        value+=1;
        value = value*2;
        if(DEBUG) Serial.print((int)1);
      }
      else if(time - (long)TimerValue[change_count-1] * 4 < 1000)
      {
        value = value*2;
        if(DEBUG) Serial.print((int)0);       
      }
    }
    change_count++;  
  }
  if(DEBUG) Serial.print("  (");
  if(DEBUG) Serial.print(value);
  if(DEBUG) Serial.println(") end");
  delay(200); 
 
  return value;
}
 
 
/*
void volumeDOWN()
{
        //1     HIGH            8120
        oscillationWrite(led_pin, 8120);
        //2     LOW             3880
        delayMicroseconds(3880);
        //3     HIGH            568
        oscillationWrite(led_pin, 568);
        //4     LOW             1420
        delayMicroseconds(1420);
        //5     HIGH            572
        oscillationWrite(led_pin, 572);
        //6     LOW             428
        delayMicroseconds(428);
        //7     HIGH            580
        oscillationWrite(led_pin, 580);
        //8     LOW             416
        delayMicroseconds(416);
        //9     HIGH            572
        oscillationWrite(led_pin, 572);
        //10    LOW             420
        delayMicroseconds(420);
        //11    HIGH            576
        oscillationWrite(led_pin, 576);
        //12    LOW             424
        delayMicroseconds(424);
        //13    HIGH            572
        oscillationWrite(led_pin, 572);
        //14    LOW             428
        delayMicroseconds(428);
        //15    HIGH            572
        oscillationWrite(led_pin, 572);
        //16    LOW             420
        delayMicroseconds(420);
        //17    HIGH            572
        oscillationWrite(led_pin, 572);
        //18    LOW             428
        delayMicroseconds(428);
        //19    HIGH            572
        oscillationWrite(led_pin, 572);
        //20    LOW             3904
        delayMicroseconds(3904);
        //21    HIGH            568
        oscillationWrite(led_pin, 568);
        //22    LOW             428
        delayMicroseconds(428);
        //23    HIGH            568
        oscillationWrite(led_pin, 568);
        //24    LOW             428
        delayMicroseconds(428);
        //25    HIGH            572
        oscillationWrite(led_pin, 572);
        //26    LOW             1420
        delayMicroseconds(1420);
        //27    HIGH            568
        oscillationWrite(led_pin, 568);
        //28    LOW             428
        delayMicroseconds(428);
        //29    HIGH            568
        oscillationWrite(led_pin, 568);
        //30    LOW             428
        delayMicroseconds(428);
        //31    HIGH            572
        oscillationWrite(led_pin, 572);
        //32    LOW             428
        delayMicroseconds(428);
        //33    HIGH            568
        oscillationWrite(led_pin, 568);
        //34    LOW             428
        delayMicroseconds(428);
        //35    HIGH            568
        oscillationWrite(led_pin, 568);
        //36    LOW             428
        delayMicroseconds(428);
        //37    HIGH            572
        oscillationWrite(led_pin, 572);
        //38    LOW             24752
        delayMicroseconds(24752);
        //39    HIGH            8052
        oscillationWrite(led_pin, 8052);
        //40    LOW             3892
        delayMicroseconds(3892);
        //41    HIGH            572
        oscillationWrite(led_pin, 572);
        //42    LOW             1420
        delayMicroseconds(1420);
        //43    HIGH            568
        oscillationWrite(led_pin, 568);
        //44    LOW             432
        delayMicroseconds(432);
        //45    HIGH            568
        oscillationWrite(led_pin, 568);
        //46    LOW             428
        delayMicroseconds(428);
        //47    HIGH            568
        oscillationWrite(led_pin, 568);
        //48    LOW             428
        delayMicroseconds(428);
        //49    HIGH            568
        oscillationWrite(led_pin, 568);
        //50    LOW             432
        delayMicroseconds(432);
        //51    HIGH            564
        oscillationWrite(led_pin, 564);
        //52    LOW             432
        delayMicroseconds(432);
        //53    HIGH            568
        oscillationWrite(led_pin, 568);
        //54    LOW             428
        delayMicroseconds(428);
        //55    HIGH            568
        oscillationWrite(led_pin, 568);
        //56    LOW             428
        delayMicroseconds(428);
        //57    HIGH            572
        oscillationWrite(led_pin, 572);
        //58    LOW             3900
        delayMicroseconds(3900);
        //59    HIGH            572
        oscillationWrite(led_pin, 572);
        //60    LOW             424
        delayMicroseconds(424);
        //61    HIGH            572
        oscillationWrite(led_pin, 572);
        //62    LOW             428
        delayMicroseconds(428);
        //63    HIGH            572
        oscillationWrite(led_pin, 572);
        //64    LOW             1420
        delayMicroseconds(1420);
        //65    HIGH            568
        oscillationWrite(led_pin, 568);
        //66    LOW             428
        delayMicroseconds(428);
        //67    HIGH            568
        oscillationWrite(led_pin, 568);
        //68    LOW             432
        delayMicroseconds(432);
        //69    HIGH            568
        oscillationWrite(led_pin, 568);
        //70    LOW             400
        delayMicroseconds(400);
        //71    HIGH            596
        oscillationWrite(led_pin, 596);
        //72    LOW             428
        delayMicroseconds(428);
        //73    HIGH            568
        oscillationWrite(led_pin, 568);
        //74    LOW             428
        delayMicroseconds(428);
        //75    HIGH            568
        oscillationWrite(led_pin, 568);
        //76    LOW             125588
        delayMicroseconds(125588);
        //77    HIGH            8072
        oscillationWrite(led_pin, 8072);
        //78    LOW             3900
        delayMicroseconds(3900);
        //79    HIGH            592
        oscillationWrite(led_pin, 592);
        //80    LOW             1400
        delayMicroseconds(1400);
        //81    HIGH            592
        oscillationWrite(led_pin, 592);
        //82    LOW             404
        delayMicroseconds(404);
        //83    HIGH            592
        oscillationWrite(led_pin, 592);
        //84    LOW             404
        delayMicroseconds(404);
        //85    HIGH            596
        oscillationWrite(led_pin, 596);
        //86    LOW             400
        delayMicroseconds(400);
        //87    HIGH            600
        oscillationWrite(led_pin, 600);
        //88    LOW             400
        delayMicroseconds(400);
        //89    HIGH            596
        oscillationWrite(led_pin, 596);
        //90    LOW             400
        delayMicroseconds(400);
        //91    HIGH            596
        oscillationWrite(led_pin, 596);
        //92    LOW             404
        delayMicroseconds(404);
        //93    HIGH            596
        oscillationWrite(led_pin, 596);
        //94    LOW             400
        delayMicroseconds(400);
        //95    HIGH            596
        oscillationWrite(led_pin, 596);
        //96    LOW             3876
        delayMicroseconds(3876);
        //97    HIGH            596
        oscillationWrite(led_pin, 596);
        //98    LOW             400
        delayMicroseconds(400);
        //99    HIGH            596
        oscillationWrite(led_pin, 596);
        //100   LOW             404
        delayMicroseconds(404);
        //101   HIGH            592
        oscillationWrite(led_pin, 592);
        //102   LOW             1396
        delayMicroseconds(1396);
        //103   HIGH            596
        oscillationWrite(led_pin, 596);
        //104   LOW             404
        delayMicroseconds(404);
        //105   HIGH            592
        oscillationWrite(led_pin, 592);
        //106   LOW             404
        delayMicroseconds(404);
        //107   HIGH            588
        oscillationWrite(led_pin, 588);
        //108   LOW             404
        delayMicroseconds(404);
        //109   HIGH            592
        oscillationWrite(led_pin, 592);
        //110   LOW             408
        delayMicroseconds(408);
        //111   HIGH            588
        oscillationWrite(led_pin, 588);
        //112   LOW             408
        delayMicroseconds(408);
        //113   HIGH            588
        oscillationWrite(led_pin, 588); 
}
void volumeUP()
{
           //1     HIGH            8072
        oscillationWrite(led_pin, 8072);
        //2     LOW             3904
        delayMicroseconds(3904);
        //3     HIGH            572
        oscillationWrite(led_pin, 572);
        //4     LOW             1416
        delayMicroseconds(1416);
        //5     HIGH            572
        oscillationWrite(led_pin, 572);
        //6     LOW             428
        delayMicroseconds(428);
        //7     HIGH            568
        oscillationWrite(led_pin, 568);
        //8     LOW             432
        delayMicroseconds(432);
        //9     HIGH            568
        oscillationWrite(led_pin, 568);
        //10    LOW             424
        delayMicroseconds(424);
        //11    HIGH            568
        oscillationWrite(led_pin, 568);
        //12    LOW             432
        delayMicroseconds(432);
        //13    HIGH            568
        oscillationWrite(led_pin, 568);
        //14    LOW             428
        delayMicroseconds(428);
        //15    HIGH            568
        oscillationWrite(led_pin, 568);
        //16    LOW             428
        delayMicroseconds(428);
        //17    HIGH            568
        oscillationWrite(led_pin, 568);
        //18    LOW             432
        delayMicroseconds(432);
        //19    HIGH            568
        oscillationWrite(led_pin, 568);
        //20    LOW             3900
        delayMicroseconds(3900);
        //21    HIGH            572
        oscillationWrite(led_pin, 572);
        //22    LOW             1424
        delayMicroseconds(1424);
        //23    HIGH            568
        oscillationWrite(led_pin, 568);
        //24    LOW             1420
        delayMicroseconds(1420);
        //25    HIGH            568
        oscillationWrite(led_pin, 568);
        //26    LOW             428
        delayMicroseconds(428);
        //27    HIGH            572
        oscillationWrite(led_pin, 572);
        //28    LOW             424
        delayMicroseconds(424);
        //29    HIGH            572
        oscillationWrite(led_pin, 572);
        //30    LOW             428
        delayMicroseconds(428);
        //31    HIGH            572
        oscillationWrite(led_pin, 572);
        //32    LOW             424
        delayMicroseconds(424);
        //33    HIGH            572
        oscillationWrite(led_pin, 572);
        //34    LOW             428
        delayMicroseconds(428);
        //35    HIGH            568
        oscillationWrite(led_pin, 568);
        //36    LOW             428
        delayMicroseconds(428);
        //37    HIGH            568
        oscillationWrite(led_pin, 568);
        //38    LOW             24752
        delayMicroseconds(24752);
        //39    HIGH            8044
        oscillationWrite(led_pin, 8044);
        //40    LOW             3904
        delayMicroseconds(3904);
        //41    HIGH            572
        oscillationWrite(led_pin, 572);
        //42    LOW             1420
        delayMicroseconds(1420);
        //43    HIGH            568
        oscillationWrite(led_pin, 568);
        //44    LOW             428
        delayMicroseconds(428);
        //45    HIGH            572
        oscillationWrite(led_pin, 572);
        //46    LOW             424
        delayMicroseconds(424);
        //47    HIGH            572
        oscillationWrite(led_pin, 572);
        //48    LOW             424
        delayMicroseconds(424);
        //49    HIGH            572
        oscillationWrite(led_pin, 572);
        //50    LOW             428
        delayMicroseconds(428);
        //51    HIGH            568
        oscillationWrite(led_pin, 568);
        //52    LOW             428
        delayMicroseconds(428);
        //53    HIGH            584
        oscillationWrite(led_pin, 584);
        //54    LOW             412
        delayMicroseconds(412);
        //55    HIGH            580
        oscillationWrite(led_pin, 580);
        //56    LOW             420
        delayMicroseconds(420);
        //57    HIGH            584
        oscillationWrite(led_pin, 584);
        //58    LOW             3888
        delayMicroseconds(3888);
        //59    HIGH            568
        oscillationWrite(led_pin, 568);
        //60    LOW             1424
        delayMicroseconds(1424);
        //61    HIGH            568
        oscillationWrite(led_pin, 568);
        //62    LOW             1420
        delayMicroseconds(1420);
        //63    HIGH            572
        oscillationWrite(led_pin, 572);
        //64    LOW             424
        delayMicroseconds(424);
        //65    HIGH            584
        oscillationWrite(led_pin, 584);
        //66    LOW             416
        delayMicroseconds(416);
        //67    HIGH            588
        oscillationWrite(led_pin, 588);
        //68    LOW             408
        delayMicroseconds(408);
        //69    HIGH            588
        oscillationWrite(led_pin, 588);
        //70    LOW             412
        delayMicroseconds(412);
        //71    HIGH            588
        oscillationWrite(led_pin, 588);
        //72    LOW             408
        delayMicroseconds(408);
        //73    HIGH            584
        oscillationWrite(led_pin, 584);
        //74    LOW             412
        delayMicroseconds(412);
        //75    HIGH            584
        oscillationWrite(led_pin, 584);
        //76    LOW             24736
        delayMicroseconds(24736);
        //77    HIGH            8052
        oscillationWrite(led_pin, 8052);
        //78    LOW             3900
        delayMicroseconds(3900);
        //79    HIGH            588
        oscillationWrite(led_pin, 588);
        //80    LOW             1404
        delayMicroseconds(1404);
        //81    HIGH            580
        oscillationWrite(led_pin, 580);
        //82    LOW             416
        delayMicroseconds(416);
        //83    HIGH            580
        oscillationWrite(led_pin, 580);
        //84    LOW             416
        delayMicroseconds(416);
        //85    HIGH            584
        oscillationWrite(led_pin, 584);
        //86    LOW             412
        delayMicroseconds(412);
        //87    HIGH            584
        oscillationWrite(led_pin, 584);
        //88    LOW             412
        delayMicroseconds(412);
        //89    HIGH            588
        oscillationWrite(led_pin, 588);
        //90    LOW             412
        delayMicroseconds(412);
        //91    HIGH            584
        oscillationWrite(led_pin, 584);
        //92    LOW             412
        delayMicroseconds(412);
        //93    HIGH            588
        oscillationWrite(led_pin, 588);
        //94    LOW             412
        delayMicroseconds(412);
        //95    HIGH            584
        oscillationWrite(led_pin, 584);
        //96    LOW             3888
        delayMicroseconds(3888);
        //97    HIGH            568
        oscillationWrite(led_pin, 568);
        //98    LOW             1420
        delayMicroseconds(1420);
        //99    HIGH            572
        oscillationWrite(led_pin, 572);
        //100   LOW             1420
        delayMicroseconds(1420);
        //101   HIGH            572
        oscillationWrite(led_pin, 572);
        //102   LOW             424
        delayMicroseconds(424);
        //103   HIGH            584
        oscillationWrite(led_pin, 584);
        //104   LOW             412
        delayMicroseconds(412);
        //105   HIGH            584
        oscillationWrite(led_pin, 584);
        //106   LOW             416
        delayMicroseconds(416);
        //107   HIGH            572
        oscillationWrite(led_pin, 572);
        //108   LOW             424
        delayMicroseconds(424);
        //109   HIGH            580
        oscillationWrite(led_pin, 580);
        //110   LOW             416
        delayMicroseconds(416);
        //111   HIGH            568
        oscillationWrite(led_pin, 568);
        //112   LOW             432
        delayMicroseconds(432);
        //113   HIGH            580
        oscillationWrite(led_pin, 580); 
}*/
/*
void power()
{
 //1     HIGH            8076
        oscillationWrite(led_pin, 8076);
        //2     LOW             3900
        delayMicroseconds(3900);
        //3     HIGH            572
        oscillationWrite(led_pin, 572);
        //4     LOW             1420
        delayMicroseconds(1420);
        //5     HIGH            568
        oscillationWrite(led_pin, 568);
        //6     LOW             432
        delayMicroseconds(432);
        //7     HIGH            568
        oscillationWrite(led_pin, 568);
        //8     LOW             428
        delayMicroseconds(428);
        //9     HIGH            568
        oscillationWrite(led_pin, 568);
        //10    LOW             428
        delayMicroseconds(428);
        //11    HIGH            568
        oscillationWrite(led_pin, 568);
        //12    LOW             428
        delayMicroseconds(428);
        //13    HIGH            568
        oscillationWrite(led_pin, 568);
        //14    LOW             432
        delayMicroseconds(432);
        //15    HIGH            568
        oscillationWrite(led_pin, 568);
        //16    LOW             428
        delayMicroseconds(428);
        //17    HIGH            568
        oscillationWrite(led_pin, 568);
        //18    LOW             428
        delayMicroseconds(428);
        //19    HIGH            572
        oscillationWrite(led_pin, 572);
        //20    LOW             3900
        delayMicroseconds(3900);
        //21    HIGH            572
        oscillationWrite(led_pin, 572);
        //22    LOW             424
        delayMicroseconds(424);
        //23    HIGH            572
        oscillationWrite(led_pin, 572);
        //24    LOW             1424
        delayMicroseconds(1424);
        //25    HIGH            564
        oscillationWrite(led_pin, 564);
        //26    LOW             1424
        delayMicroseconds(1424);
        //27    HIGH            568
        oscillationWrite(led_pin, 568);
        //28    LOW             1424
        delayMicroseconds(1424);
        //29    HIGH            568
        oscillationWrite(led_pin, 568);
        //30    LOW             424
        delayMicroseconds(424);
        //31    HIGH            576
        oscillationWrite(led_pin, 576);
        //32    LOW             424
        delayMicroseconds(424);
        //33    HIGH            572
        oscillationWrite(led_pin, 572);
        //34    LOW             424
        delayMicroseconds(424);
        //35    HIGH            572
        oscillationWrite(led_pin, 572);
        //36    LOW             424
        delayMicroseconds(424);
        //37    HIGH            572
        oscillationWrite(led_pin, 572);
        //38    LOW             24752
        delayMicroseconds(24752);
        //39    HIGH            8044
        oscillationWrite(led_pin, 8044);
        //40    LOW             3904
        delayMicroseconds(3904);
        //41    HIGH            568
        oscillationWrite(led_pin, 568);
        //42    LOW             1424
        delayMicroseconds(1424);
        //43    HIGH            568
        oscillationWrite(led_pin, 568);
        //44    LOW             428
        delayMicroseconds(428);
        //45    HIGH            572
        oscillationWrite(led_pin, 572);
        //46    LOW             424
        delayMicroseconds(424);
        //47    HIGH            572
        oscillationWrite(led_pin, 572);
        //48    LOW             424
        delayMicroseconds(424);
        //49    HIGH            572
        oscillationWrite(led_pin, 572);
        //50    LOW             428
        delayMicroseconds(428);
        //51    HIGH            568
        oscillationWrite(led_pin, 568);
        //52    LOW             428
        delayMicroseconds(428);
        //53    HIGH            568
        oscillationWrite(led_pin, 568);
        //54    LOW             428
        delayMicroseconds(428);
        //55    HIGH            572
        oscillationWrite(led_pin, 572);
        //56    LOW             428
        delayMicroseconds(428);
        //57    HIGH            568
        oscillationWrite(led_pin, 568);
        //58    LOW             3904
        delayMicroseconds(3904);
        //59    HIGH            568
        oscillationWrite(led_pin, 568);
        //60    LOW             428
        delayMicroseconds(428);
        //61    HIGH            572
        oscillationWrite(led_pin, 572);
        //62    LOW             1420
        delayMicroseconds(1420);
        //63    HIGH            568
        oscillationWrite(led_pin, 568);
        //64    LOW             1420
        delayMicroseconds(1420);
        //65    HIGH            572
        oscillationWrite(led_pin, 572);
        //66    LOW             1420
        delayMicroseconds(1420);
        //67    HIGH            568
        oscillationWrite(led_pin, 568);
        //68    LOW             432
        delayMicroseconds(432);
        //69    HIGH            564
        oscillationWrite(led_pin, 564);
        //70    LOW             432
        delayMicroseconds(432);
        //71    HIGH            568
        oscillationWrite(led_pin, 568);
        //72    LOW             428
        delayMicroseconds(428);
        //73    HIGH            568
        oscillationWrite(led_pin, 568);
        //74    LOW             432
        delayMicroseconds(432);
        //75    HIGH            564
        oscillationWrite(led_pin, 564);
        //76    LOW             68600
        delayMicroseconds(68600);
        //77    HIGH            8072
        oscillationWrite(led_pin, 8072);
        //78    LOW             3912
        delayMicroseconds(3912);
        //79    HIGH            560
        oscillationWrite(led_pin, 560);
        //80    LOW             1420
        delayMicroseconds(1420);
        //81    HIGH            572
        oscillationWrite(led_pin, 572);
        //82    LOW             428
        delayMicroseconds(428);
        //83    HIGH            572
        oscillationWrite(led_pin, 572);
        //84    LOW             424
        delayMicroseconds(424);
        //85    HIGH            572
        oscillationWrite(led_pin, 572);
        //86    LOW             424
        delayMicroseconds(424);
        //87    HIGH            572
        oscillationWrite(led_pin, 572);
        //88    LOW             428
        delayMicroseconds(428);
        //89    HIGH            568
        oscillationWrite(led_pin, 568);
        //90    LOW             432
        delayMicroseconds(432);
        //91    HIGH            564
        oscillationWrite(led_pin, 564);
        //92    LOW             432
        delayMicroseconds(432);
        //93    HIGH            568
        oscillationWrite(led_pin, 568);
        //94    LOW             448
        delayMicroseconds(448);
        //95    HIGH            548
        oscillationWrite(led_pin, 548);
        //96    LOW             3900
        delayMicroseconds(3900);
        //97    HIGH            576
        oscillationWrite(led_pin, 576);
        //98    LOW             424
        delayMicroseconds(424);
        //99    HIGH            572
        oscillationWrite(led_pin, 572);
        //100   LOW             1420
        delayMicroseconds(1420);
        //101   HIGH            568
        oscillationWrite(led_pin, 568);
        //102   LOW             1424
        delayMicroseconds(1424);
        //103   HIGH            568
        oscillationWrite(led_pin, 568);
        //104   LOW             1420
        delayMicroseconds(1420);
        //105   HIGH            568
        oscillationWrite(led_pin, 568);
        //106   LOW             428
        delayMicroseconds(428);
        //107   HIGH            568
        oscillationWrite(led_pin, 568);
        //108   LOW             432
        delayMicroseconds(432);
        //109   HIGH            568
        oscillationWrite(led_pin, 568);
        //110   LOW             428
        delayMicroseconds(428);
        //111   HIGH            568
        oscillationWrite(led_pin, 568);
        //112   LOW             432
        delayMicroseconds(432);
        //113   HIGH            568
        oscillationWrite(led_pin, 568);
        //114   LOW             24752
        delayMicroseconds(24752);
        //115   HIGH            8044
        oscillationWrite(led_pin, 8044);
        //116   LOW             3904
        delayMicroseconds(3904);
        //117   HIGH            568
        oscillationWrite(led_pin, 568);
        //118   LOW             1420
        delayMicroseconds(1420);
        //119   HIGH            572
        oscillationWrite(led_pin, 572);
        //120   LOW             428
        delayMicroseconds(428);
        //121   HIGH            568
        oscillationWrite(led_pin, 568);
        //122   LOW             448
        delayMicroseconds(448);
        //123   HIGH            548
        oscillationWrite(led_pin, 548);
        //124   LOW             428
        delayMicroseconds(428);
        //125   HIGH            568
        oscillationWrite(led_pin, 568);
        //126   LOW             428
        delayMicroseconds(428);
        //127   HIGH            568
        oscillationWrite(led_pin, 568);
        //128   LOW             432
        delayMicroseconds(432);
        //129   HIGH            568
        oscillationWrite(led_pin, 568);
        //130   LOW             428
        delayMicroseconds(428);
        //131   HIGH            568
        oscillationWrite(led_pin, 568);
        //132   LOW             428
        delayMicroseconds(428);
        //133   HIGH            568
        oscillationWrite(led_pin, 568);
        //134   LOW             3904
        delayMicroseconds(3904);
        //135   HIGH            568
        oscillationWrite(led_pin, 568);
        //136   LOW             432
        delayMicroseconds(432);
        //137   HIGH            568
        oscillationWrite(led_pin, 568);
        //138   LOW             1424
        delayMicroseconds(1424);
        //139   HIGH            568
        oscillationWrite(led_pin, 568);
        //140   LOW             1420
        delayMicroseconds(1420);
        //141   HIGH            572
        oscillationWrite(led_pin, 572);
        //142   LOW             1420
        delayMicroseconds(1420);
        //143   HIGH            568
        oscillationWrite(led_pin, 568);   
}*/
 
void oscillationWrite(int pin, int time) 
{
  for(int i = 0; i <= time/26; i++) {
    digitalWrite(pin, HIGH);
    delayMicroseconds(13);
    digitalWrite(pin, LOW);
    delayMicroseconds(13);
  }
}