38 kHzの発振をArduinoで行う場合のスケッチです。

// This is the IR-remote controller for Arduino //
// Power on/off  Leader+1010100010110011111 for Sony DPF-V700
// Leader 2.4(high)+0.6(low)=3.0 msec
// 1: 1.2(high)+0.6(low)=1.8 msec、
// 0: 0.6(high)+0.6(low)=1.2 msec

unsigned int T1=600; // Low time or High time of Zero
unsigned int T2=1200; // High time of One
unsigned int T4=2400; //High time of Leader
unsigned int T18=10800; // Low time of the bottom line
unsigned int Tdelay=13;  // 38kHz 
unsigned int T1Repeat=22; // 22 waves in 0.6 msec 
unsigned int T2Repeat=45; // 45 waves in 1.2 msec
unsigned int T4Repeat=90; // 90 waves in 2.4 msec
unsigned long Time=0;


void setup(){
  pinMode(2, OUTPUT); //No 2 pin =output
}

void Leader(){ 
  for (int i=0; i<T4Repeat; i++){ //38kHz frequency 90 waves
       PORTD=B00000100;
      delayMicroseconds(Tdelay);  //on for Tdelay
        PORTD=B00000000;
      delayMicroseconds(Tdelay);  //off for Tdelay
      }    
    digitalWrite(2, LOW);    // 
      delayMicroseconds(T1);  //off for T1
}

void One(){ 
     for (int i=0; i<T2Repeat; i++){ //38kHz frequency 45 waves
         PORTD=B00000100;
      delayMicroseconds(Tdelay);  //on for Tdelay
         PORTD=B00000000;
      delayMicroseconds(Tdelay);  //off for Tdelay
      }  
    digitalWrite(2, LOW);    
      delayMicroseconds(T1);  //off for T1
}

void Zero(){ 
    for (int i=0; i<T1Repeat; i++){ 
       PORTD=B00000100; 
      delayMicroseconds(Tdelay);  //on for Tdelay
       PORTD=B00000000;
      delayMicroseconds(Tdelay);  //off for Tdelay
      }  
      digitalWrite(2, LOW);    
      delayMicroseconds(T1);  //off for T1
}

void SignalOnOff(){ //send Leader+10101000101100111111
  Leader();
  One();
     Zero();
  One();
     Zero();
  One();
     Zero();
     Zero();
     Zero();
  One();
     Zero();
  One();
  One();
     Zero();
     Zero();
  One();
  One();
  One();
  One();
  One();
  One();
      delayMicroseconds(T18);  //off for 10800 usec 
}

void loop(){  //main program
 // send Leader+ 10101000101100111111 for three times
  SignalOnOff();
  SignalOnOff();
  SignalOnOff();
   delay(30000);  //wait 30 sec
}

戸田よろず研究所トップページへ

ここで公開するアイデア/装置は安全性を保障しておりません。 用途に応じた設計を行い、十分な安全検査を行ってからご利用ください。 本サイトの情報の営利目的での利用はご遠慮ください。 本サイトの内容の無断転載を禁じます。© 2010 TYK