0

您好,我使用的是 arduino mkr1000,因此使用mkr1000 IRremote 库的 IRremote 库发送和 IR 信号。我在使用 IRsend 时遇到问题。

首先,我使用 IRdump 示例从远程按钮获取数据。完成此操作后,我尝试了 IRsend 示例,但它似乎无法正常工作。

我暂时换了一个普通的LED来显示它是否真的在闪烁,但事实并非如此。我已经测试了它们工作的普通 LED 和 IR LED。

我还认为我根据示例正确连接了 LED

引脚 3 -> LED -> 电阻器 -> 接地

当我上传一个让它闪烁的草图时,我的电路被进一步确认是正确的。

基本上我正在尝试发送 NEC 32 位信号 0x2FD807F

但我猜他们无法完成 mkr1000 的发送库???

这篇文章中,使用代码发表了评论,但实际上并没有详细说明如何使用它。

这是我目前所在的地方

int IR_S =  3;

void setup()
{
  pinMode(IR_S,OUTPUT);
}

void loop() {

  IR_Sendcode(0x2FD807F);
  delay(1000); 
}



void IR_Send38KHZ(int x,int bit)      //Generate 38KHZ IR pulse
{      
     for(int i=0;i<x;i++)//15=386US
     {      
          if(bit==1)
          {
         digitalWrite(IR_S,1);
           delayMicroseconds(9);
         digitalWrite(IR_S,0);
           delayMicroseconds(9);
          }
          else 
          {
         digitalWrite(IR_S,0);
           delayMicroseconds(20);
          }            
     }
}

void IR_Sendcode(uint8_t data)      // Send the data
{
   for(int i=0;i<8;i++)
    {
      if((data&0x01)==0x01)
       {
          IR_Send38KHZ(23,1);
          IR_Send38KHZ(64,0);             
       }
       else 
        {
           IR_Send38KHZ(23,1);
           IR_Send38KHZ(21,0);  
        }
      data=data>>1;
    }  
}

4

1 回答 1

2

我在等待回复时创建了自己的代码。我已经完成并测试了它。它理论上应该适用于任何arduino。

/*
  This is a code for NEC Infrared Transmission Protocol Transmitter

  NEC specifications are

    ~ Carrier Frequency is 38kHz
    
    * Logical '0' – a 562.5µs pulse burst followed by a 562.5µs space, with a total transmit time of 1.125ms
    * Logical '1' – a 562.5µs pulse burst followed by a 1.6875ms space, with a total transmit time of 2.25ms

    - a 9ms leading pulse burst (16 times the pulse burst length used for a logical data bit)
    - a 4.5ms space
    - the 8-bit address for the receiving device
    - the 8-bit logical inverse of the address
    - the 8-bit command
    - the 8-bit logical inverse of the command
    - a final 562.5µs pulse burst to signify the end of message transmission.

  Example,
    If the code recieved from the data dump from the IRremote library is 0x2FD807F
      -0x02 is address
      -0xFD is the inverse address
      -0x80 is the command
      -0x7F is the inverse command

  THIS PROGRAM IS A BLOCKING PROGRAM
*/


#define IR 3
#define CarrierFreqInterval 11

void setup() {
  pinMode(IR, OUTPUT);
  digitalWrite(IR, LOW);
}

void loop() {
//  unsigned long start = micros();

  transmit(0x02FD807F);

//  unsigned long ends = micros();
//  unsigned long delta = ends - start;
//  Serial.println(delta);

  delay(500);
}


void transmit(uint32_t data) {
  //Function for transmiting the data

  uint32_t bitcount = 0x80000000;

  // 9ms pulse burst
  for (int i = 0; i < 355; i++) {
    digitalWrite(IR, HIGH);
    delayMicroseconds(CarrierFreqInterval);
    digitalWrite(IR, LOW);
    delayMicroseconds(CarrierFreqInterval);
  }


  // 4.5ms space
  delayMicroseconds(4500);



  //8bit address,adress inverse,command,command inverse
  while ( bitcount != 0b0) {
    if ((data & bitcount) == bitcount) {
      pulseHIGH();
    }
    else {
      pulseLOW();
    }

    bitcount = bitcount >> 1;
  }


  //final pulse burst
  for (int i = 0; i < 21; i++) {
    digitalWrite(IR, HIGH);
    delayMicroseconds(CarrierFreqInterval);
    digitalWrite(IR, LOW);
    delayMicroseconds(CarrierFreqInterval);
  }
}

void pulseHIGH() {
  // Pulse 38KHz good for a LOGIC '1'
  
  for (int i = 0; i < 21; i++) {
    digitalWrite(IR, HIGH);
    delayMicroseconds(CarrierFreqInterval);
    digitalWrite(IR, LOW);
    delayMicroseconds(CarrierFreqInterval);
  }
  delay(1);
  delayMicroseconds(687.5);
}

void pulseLOW() {
  // Pulse 38KHz good for a LOGIC '0'

  for (int i = 0; i < 21; i++) {
    digitalWrite(IR, HIGH);
    delayMicroseconds(CarrierFreqInterval);
    digitalWrite(IR, LOW);
    delayMicroseconds(CarrierFreqInterval);
  }
  delayMicroseconds(562.5);

}

于 2019-07-17T18:12:33.107 回答