Sending IR signal from Arduino to F&D speakers

2019-08-16 01:15发布

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);
    }
}

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
  }
}

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.

1条回答
爷的心禁止访问
2楼-- · 2019-08-16 01:49

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

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' or 'U' to force the constant into an unsigned data format. Example: 33u

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

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

And from GitHub:

void sendNEC (unsigned long data, int nbits) ;

So, try:

irsend.sendNEC(0x01FE08F7UL,32);
查看更多
登录 后发表回答