从 Arduino 向 F&D 扬声器发送 IR 信号 [英] Sending IR signal from Arduino to F&D speakers

查看:18
本文介绍了从 Arduino 向 F&D 扬声器发送 IR 信号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码向我的扬声器发送 IR 信号,但他们没有响应.

I am using below code to send an IR signal to my speaker but they don't respond.

#include <IRremote.h>

IRsend irsend;
const int buttonPin = 8; // the number of the pushbutton pin
//const int ledPin = 3;
int buttonState = 0; // variable for reading the pushbutton status
void setup()
{
    // pinMode(ledPin, OUTPUT);
    // initialize the pushbutton pin as an input:
    pinMode(buttonPin, INPUT);
    Serial.begin(9600);
}

void loop() {

    buttonState = digitalRead(buttonPin);

    // check if the pushbutton is pressed.
    // if it is, the buttonState is HIGH:
    if (buttonState == HIGH) {
        // turn LED on:
        digitalWrite(7,HIGH);
        irsend.sendNEC(0x1FE08F7,32);
    }else{
        digitalWrite(7,LOW);
    }
}

我的另一个 Arduino 上的 IR 接收器接收到信号,但它们也有所不同,有时显示 UNKNOWN,有时显示 NEC.我正在使用以下代码:

IR Reciever on my other Arduino receives signal but also they vary sometime it shows UNKNOWN and sometime NEC. I am using below code:

#include <IRremote.h>

const int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  irrecv.blink13(true);
}

void loop() {
  if (irrecv.decode(&results)) {
    if (results.decode_type == NEC) {
      Serial.print("NEC: ");
    } else if (results.decode_type == SONY) {
      Serial.print("SONY: ");
    } else if (results.decode_type == RC5) {
      Serial.print("RC5: ");
    } else if (results.decode_type == RC6) {
      Serial.print("RC6: ");
    } else if (results.decode_type == UNKNOWN) {
      Serial.print("UNKNOWN: ");
    }
    Serial.println(results.value, HEX);
     Serial.println(results.value);
    irrecv.resume(); // Receive the next value
  }
}

我收到的 NEC 代码是正确的,但在该代码上扬声器没有响应.我用扬声器附带的遥控器仔细检查了 HEX 代码,但似乎没有任何效果.

The NEC code that I recieved is correct but on that code speaker does not respond. I double checked the HEX code with the remote that came along with speaker but nothing seem to work.

推荐答案

我认为您可能对 HEX 文字有问题.来自 Arduino API:

I think that you could have problem with the HEX literal. From Arduino API:

默认情况下,整数常量被视为 int 值,并有相应的值限制.要使用另一种数据类型指定整数常量,请在后面加上:

By default, an integer constant is treated as an int with the attendant limitations in values. To specify an integer constant with another data type, follow it with:

a 'u' 或 'U' 强制常量为无符号数据格式.示例:33u

a 'u' or 'U' to force the constant into an unsigned data format. Example: 33u

a 'l' 或 'L' 强制常量为长数据格式.示例:100000L

a 'l' or 'L' to force the constant into a long data format. Example: 100000L

'ul' 或 'UL' 将常量强制为无符号长常量.示例:32767ul

a 'ul' or 'UL' to force the constant into an unsigned long constant. Example: 32767ul

来自 GitHub:

void sendNEC (unsigned long data, int nbits);

void sendNEC (unsigned long data, int nbits) ;

所以,尝试:

irsend.sendNEC(0x01FE08F7UL,32);

这篇关于从 Arduino 向 F&D 扬声器发送 IR 信号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆