Inviare e riceve segnali infrarossi

Salve a tutti, volevo provare a utilizzare il mio televisore Sony, con un telecomando Nec. Sto utilizzando la libreria di Ken Shirriff, ma il problema è che non riesco a ricevere e inviare allo stesso momento. Ho letto che, dopo aver inviato, bisogna riabilitare la ricezione con il comando irrecv.enableIRIn();. ma nulla. Il codice che sto utilizzando è questo:

#include <IRremote.h>

int receiver = 11;

IRrecv irrecv(receiver);
IRsend irsend;
decode_results results;
 
void setup() {
  Serial.begin(9600);
  irrecv.enableIRIn();
}

unsigned int ON[68]={2450,550,1200,550,1200,550,650,550,650,550,1200,550,650,550,600,550,1250,550,600,550,650,550,650,500,650};

void loop() {
  if (irrecv.decode(&results)){
    Serial.print(results.value);
    irrecv.resume();
    irsend.sendRaw(ON,68,38);
    delay(50);
    irrecv.enableIRIn();
  }
}

E il telecomando riesce solo a ricevere e non ad inviare. Se, invece, elimino l'if, non ricevo nulla (infatti il Serial.print non stampa), ma al contrario riesce ad inviare il segnale (in questo caso diminuendo il volume della televisione). Come andrebbero utilizzate le due cose assieme?

Grazie per l'aiuto!

void loop () {
if (irrecv.decode (& results)) {
Serial.print (results.value);
irrecv.resume ();
delay(50); //<<<<<<<<<<<<<<<<<<<<<<<<<<<<??????? or delay(100);???
irsend.sendRaw (ON, 68,40); //<<<<<<<<<<< Sony = 40kHz
delay (50);
irrecv.enableIRIn ();
}
}

??? :slight_smile:

// NB: Not all protocols are supported by IRremote or IRLib. You may need to edit the code below manually
// Automatically Generated by AnalysIR for xxxxxxxx, visit http://www.AnalysIR.com or email info@....... for further details
irsend.sendSony(0xC90, 12); // AnalysIR IR Protocol: SONY, Key:
/*
Automatically Generated by AnalysIR - Batch Export Utility
Registered to: xxxxxxxx
Session History
Type : Key : Value : Bits
0 : RAW :  :  : 12
*/

// NB: Not all protocols are supported by IRremote or IRLib. You may need to edit the code below manually
// Automatically Generated by AnalysIR for xxxxxxxx, visit http://www.AnalysIR.com or email info@....... for further details
int khz=40; //NB Change this default value as neccessary to the correct modulation frequency


unsigned int Signal_0_0[] = {2400,600,1200,600,1200,600,600,600,600,600,1200,600,600,600,600,600,1200,600,600,600,600,600,600,600,600,7200}; //AnalysIR Batch Export - RAW

irsend.sendRaw(Signal_0_0, sizeof(Signal_0_0)/sizeof(int), khz); //AnalysIR Batch Export - RAW
 // AnalysIR IR Protocol: RAW, Key:

Ty so much now all works :), with a delay of 100ms and the right requency.

:slight_smile: