**My code Boolean part is towards the end **
int Volumedown[] = {
// ON, OFF (in 10’s of microseconds)
884, 434,
58, 52,
58, 52,
58, 160,
60, 50,
60, 50,
58, 52,
58, 52,
58, 50,
58, 162,
58, 162,
58, 50,
58, 162,
58, 162,
58, 162,
58, 160,
60, 160,
58, 162,
58, 162,
58, 50,
58, 52,
58, 52,
58, 52,
58, 50,
58, 52,
58, 52,
58, 50,
60, 160,
58, 162,
58, 162,
58, 160,
60, 160,
58, 162,
58, 3954,
884, 218,
58, 2892,
884, 218,
56, 0};
int Volumeup[] = {
// ON, OFF (in 10’s of microseconds)
884, 434,
58, 52,
58, 52,
58, 162,
58, 50,
58, 52,
58, 52,
58, 50,
60, 50,
58, 162,
58, 162,
58, 50,
58, 162,
58, 162,
58, 162,
58, 160,
58, 162,
58, 52,
58, 162,
58, 50,
58, 52,
58, 52,
58, 50,
60, 50,
58, 52,
58, 162,
58, 52,
58, 160,
58, 162,
58, 162,
58, 160,
58, 162,
58, 162,
58, 3954,
884, 218,
58, 2892,
884, 216,
60, 2892,
884, 218,
56, 2894,
884, 216,
58, 0};
int Channelup[] = {
// ON, OFF (in 10’s of microseconds)
884, 434,
58, 52,
58, 52,
56, 162,
58, 52,
58, 52,
58, 50,
60, 50,
58, 52,
58, 162,
58, 162,
56, 52,
58, 162,
58, 162,
58, 160,
60, 160,
58, 162,
58, 52,
58, 52,
56, 52,
58, 52,
58, 52,
58, 50,
58, 52,
58, 52,
58, 160,
58, 162,
58, 162,
58, 162,
58, 160,
60, 160,
58, 162,
58, 162,
58, 3954,
884, 218,
58, 2892,
884, 216,
58, 0};
int Channeldown[] = {
// ON, OFF (in 10’s of microseconds)
884, 436,
58, 50,
60, 50,
58, 162,
58, 52,
58, 50,
58, 52,
58, 52,
58, 52,
58, 160,
58, 162,
58, 52,
58, 160,
58, 162,
58, 162,
58, 162,
58, 160,
60, 160,
60, 50,
58, 52,
58, 52,
58, 50,
58, 52,
58, 52,
58, 50,
60, 50,
58, 162,
58, 162,
58, 160,
58, 162,
58, 162,
58, 162,
58, 160,
58, 3954,
884, 218,
58, 2894,
884, 216,
58, 0};
#define IRpin_PIN PIND
#define IRpin 2
#define FUZZINESS 20
// the maximum pulse we’ll listen for - 65 milliseconds is a long time
#define MAXPULSE 65000
// what our timing resolution should be, larger is better
// as its more ‘precise’ - but too large and you wont get
// accurate timing
#define RESOLUTION 20
// we will store up to 100 pulse pairs (this is -a lot-)
uint16_t pulses[100][2]; // pair is high and low pulse
uint8_t currentpulse = 0; // index for pulses we’re storing
void setup(void) {
Serial.begin(9600);
Serial.println(“Ready to decode IR!”);
}
void loop(void) {
int numberpulses;
numberpulses = listenForIR();
Serial.print(“Heard “);
Serial.print(numberpulses);
Serial.println(”-pulse long IR signal”);
if (IRcompare(numberpulses, Channelup )) {
Serial.println(“Forward”);
}
if (IRcompare(numberpulses, Channeldown)) {
Serial.println(“Backward”);
}
if (IRcompare(numberpulses, Volumeup)) {
Serial.println(“Left”);
}
if (IRcompare (numberpulses, Volumedown)) {
Serial.println (“Right”);
}
boolean IRcompare(int numpulses, int Signal[]) {
for (int i=0; i< numpulses-1; i++) {
int oncode = pulses[i][1] * RESOLUTION / 10;
int offcode = pulses[i+1][0] * RESOLUTION / 10;
if ( abs(oncode - Signal[i*2 + 0]) <= (Signal[i*2 + 0] * FUZZINESS / 100)) {
} else {
return false;
if ( abs(offcode - Signal[i*2 + 1]) <= (Signal[i*2 + 1] * FUZZINESS / 100)) {
} else {
return false;
return true;
}
int listenForIR(void) {
currentpulse = 0;
while (1) {
uint16_t highpulse, lowpulse; // temporary storage timing
highpulse = lowpulse = 0; // start out with no pulse length
// while (digitalRead(IRpin)) // this is too slow!
while (IRpin_PIN & (1 << IRpin)) {
// pin is still HIGH
// count off another few microseconds
highpulse++;
delayMicroseconds(RESOLUTION);
// If the pulse is too long, we ‘timed out’ - either nothing
// was received or the code is finished, so print what
// we’ve grabbed so far, and then reset
if ((highpulse >= MAXPULSE) && (currentpulse != 0)) {
return currentpulse;
}
}
// we didn’t time out so lets stash the reading
pulses[currentpulse][0] = highpulse;
// same as above
while (! (IRpin_PIN & _BV(IRpin))) {
// pin is still LOW
lowpulse++;
delayMicroseconds(RESOLUTION);
if ((lowpulse >= MAXPULSE) && (currentpulse != 0)) {
return currentpulse;
}
}
pulses[currentpulse][1] = lowpulse;
// we read one high-low pulse successfully, continue!
currentpulse++;
}}