After I have the corret binary array to the temperature I want, I send that to a function that I created called SendRawByBit, which was supposed to work similarly to the sendRaw function, but it's not working and I don't know why. I'm reading the documentation and I don't quite understand everything... I think the problem might be related to the irsend.mark and irsend.space methods. I'm probrably missing something...
Code: Select all
#define HEADER_MARK 9040
#define HEADER_SPACE 4450
#define MARK_DURATION 700
#define SHORT_PAUSE 700
#define LONG_PAUSE 1650
#define SHORT_DELAY 20000
#define LONG_DELAY 40000
#define TOTAL_BYTES 25
#define MESSAGE_BITS (TOTAL_BYTES*8)+1
void sendRawByBit(byte byte_array[], int khz, int temp) {
IrSender.enableIROut(khz);
// Sending Header
IrSender.mark(HEADER_MARK);
IrSender.space(HEADER_SPACE);
int idx = 2;
for (int byteIndex = 0; byteIndex < TOTAL_BYTES; byteIndex++) {
for (int bitIndex = 0; bitIndex < 8; bitIndex++) {
//700 20000
if(idx== 72 || idx == 212|| idx == 352){
IrSender.mark(MARK_DURATION);
IrSender.space(SHORT_DELAY);
idx++;
idx++;
}
//700 40000
if(idx == 138 || idx == 278){
IrSender.mark(MARK_DURATION);
IrSender.space(LONG_DELAY);
idx++;
idx++;
}
//9040 4450
if(idx == 140 || idx == 280){
IrSender.mark(HEADER_MARK);
IrSender.space(HEADER_SPACE);
idx++;
idx++;
}
// Getting current bit
int bit = (byte_array[byteIndex] >> (7 - bitIndex)) & 1;
if (bit == 1) {
IrSender.mark(MARK_DURATION);
IrSender.space(LONG_PAUSE);
idx++;
idx++;
} else {
IrSender.mark(MARK_DURATION);
IrSender.space(SHORT_PAUSE);
idx++;
idx++;
}
}
}
// Sending final bit
if(temp == 28){
IrSender.mark(MARK_DURATION);
IrSender.space(SHORT_PAUSE);
}else{
IrSender.mark(MARK_DURATION);
IrSender.space(LONG_PAUSE);
}
//sending final 700
IrSender.space(SHORT_PAUSE);
}
A normalized raw array looks like this:
Raw: 9000, 4500, 700, 1650, 700, 700, 700, 700, 700, 1650, 700, 1650, 700, 700, 700, 1650, 700, 700, 700, 1650, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 1650, 700, 1650, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 1650, 700, 700, 700, 1650, 700, 700, 700, 700, 700, 1650, 700, 700, 700, 20000, 700, 1650, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 1650, 700, 1650, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700,40000, 9000, 4500, 700, 1650, 700, 700, 700, 700, 700, 1650, 700, 1650, 700, 700, 700, 1650, 700, 700, 700, 1650, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 1650, 700, 1650, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 1650, 700, 1650, 700, 1650, 700, 700, 700, 700, 700, 1650, 700, 700, 700, 20000, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 1650, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 1650, 700, 700, 700, 1650, 700, 700, 700, 40000, 9000, 4500, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 1650, 700, 700, 700, 1650, 700, 700, 700, 1650, 700, 700, 700, 20000, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 700, 1650, 700, 700, 700, 1650, 700
All the raw arrays when converted to binary follow this sequence:
700 1650 = 1
700 700 = 0
Hh - header (9000,4000)
S = short (20000)
L = long (40000)
p - 700
Hh (35bits) pS (32bits) pLHh(35bits) pS (32bits) pLHh (35bits) pS (32bits).
The idx on the previous code is to keep track of where I need to put all those headers, short, long, and p values...
Thanks a lot.