I'm trying to decode my Panasonic tv remote using the IR_RECEIVE sketch below.
When i press the remote's buttons it works fine and i get the values, except from when i press the power button - the setup() function executes.
This is the code:
/* Raw IR decoder sketch!
This sketch/program uses the Arduno and a PNA4602 to
decode IR received. This can be used to make a IR receiver
(by looking for a particular code)
or transmitter (by pulsing an IR LED at ~38KHz for the
durations detected
Code is public domain, check out www.ladyada.net and adafruit.com
for more tutorials!
*/
#define IRpin_PIN PIND
#define IRpin 2
#define MAXPULSE 65000
#define RESOLUTION 20
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) {
uint16_t highpulse, lowpulse; // temporary storage timing
highpulse = lowpulse = 0; // start out with no pulse length
while (IRpin_PIN & (1 << IRpin)) {
highpulse++;
delayMicroseconds(RESOLUTION);
if ((highpulse >= MAXPULSE) && (currentpulse != 0)) {
printpulses();
currentpulse = 0;
return;
}
}
pulses[currentpulse][0] = highpulse;
while (!(IRpin_PIN & _BV(IRpin))) {
lowpulse++;
delayMicroseconds(RESOLUTION);
if ((lowpulse >= MAXPULSE) && (currentpulse != 0)) {
printpulses();
currentpulse = 0;
return;
}
}
pulses[currentpulse][1] = lowpulse;
currentpulse++;
}
void printpulses(void) {
Serial.println("\n\r\n\rReceived: \n\rOFF \tON");
for (uint8_t i = 0; i < currentpulse; i++) {
Serial.print("delayMicroseconds(");
Serial.print(pulses[i][0]*RESOLUTION, DEC);
Serial.println(");");
Serial.print("pulseIR(");
Serial.print(pulses[i][1]*RESOLUTION, DEC);
Serial.println(");");
}
}
This is the output:
> Ready to decode IR!
>
>
>
> Received:
>
> OFF ON
> delayMicroseconds(34724);
> pulseIR(3600);
> delayMicroseconds(1800);
> ......
> delayMicroseconds(1340);
> pulseIR(460);
> delayMicroseconds(1360);
> pulseIR(460);
> Ready to decode IR!
> Ready to decode IR!
The last 2 rows appeared when i pressed the power button (twice).
The rows above appears when i press any other button.
I played around with the Arduino and the remote, i might have done something to cause this. The first time i tried it - it worked fine.
I tried resetting and re-uploading.
Sorry if the post is too long or not informative enough- i'm new to this and not really sure what kind of information to provide.
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.