Hello..
I'm currently trying to make a connection between pin 3 on my arduino and the outpin pin of the IR receiver in my speaker system's control-pod..
The result should be, that i am able to both read incoming IR-codes received by the speaker system, and send IR codes to actually control the system..
The IR-receiver in the system is Active-low..
Here is my code:
#include <avr/pgmspace.h>
#include "codes.h"
#include <IRremote.h>
const int IR = 3;
IRrecv irrecv(IR);
decode_results results;
int incomingByte = 0;
void setup() {
pinMode(IR,INPUT);
Serial.begin(9600);
irrecv.enableIRIn();
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume();
}
if (Serial.available() > 0) {
incomingByte = Serial.read();
if(incomingByte = 49) {
sendcommand(cmd_power);
}
}
}
void sendcommand(prog_uint16_t *cmd) {
pinMode(IR,OUTPUT);
digitalWrite(IR,HIGH);
int t = 0;
int addr = 0;
for (int i=0;i<34;i++) {
addr = (i<<1);
digitalWrite(IR,LOW);
t = pgm_read_word_near(cmd+addr);
delayMicroseconds(t);
digitalWrite(IR,HIGH);
t = pgm_read_word_near(cmd+addr+1);
delayMicroseconds(t);
}
delay(200);
pinMode(IR,INPUT);
digitalWrite(IR,LOW);
}
The problem is, that the send part only works if the
irrecv.enableIRIn();
isn't there..
The
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume();
}
part works perfectly..
And the send part works perfectly aswell.. just not together.
Here is a sample of codes.h:
prog_uint16_t cmd_power[] PROGMEM = {
9100, 4450, 650, 500, 600, 550,
550, 550, 600, 1650, 600, 550,
600, 500, 600, 550, 600, 550,
550, 1700, 550, 1700, 600, 1650,
600, 500, 600, 1700, 550, 1700,
550, 1700, 600, 1650, 600, 550,
600, 500, 600, 550, 600, 500,
600, 1700, 550, 550, 600, 550,
550, 600, 550, 1700, 550, 1700,
600, 1650, 600, 1650, 600, 550,
550, 1700, 550, 1700, 600, 1650,
600
};
And the IRremote.h is the library from: A Multi-Protocol Infrared Remote Library for the Arduino
Hope you can help!
Cheers