user50501: I'm trying to decode my Panasonic television remote using the IR_RECEIVE sketch below.
When I press the remote's buttons it works fine and Iget 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.

user313: How high can currentpulse get before it is reset to zero? It is used an array index and if it gets larger than the (number of array elements-1), your code will write outside of the array.
Can the array be so far over-written that it grows into the stack area? That could definitely cause a reset, or reset-like behavior.

50501: <p>I'm trying to decode my Panasonic television remote using the IR_RECEIVE sketch below.</p>

<p>When I press the remote's buttons it works fine and Iget the values, except from when I press the power button - the setup() function executes.</p>

<p>This is the code:</p>

<pre><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 &amp; (1 &lt;&lt; IRpin)) {
        highpulse++;
        delayMicroseconds(RESOLUTION);

        if ((highpulse &gt;= MAXPULSE) &amp;&amp; (currentpulse != 0)) {
            printpulses();
            currentpulse = 0;
            return;
        }
    }
    pulses[currentpulse][0] = highpulse;

    while (!(IRpin_PIN &amp; _BV(IRpin))) {
        lowpulse++;
        delayMicroseconds(RESOLUTION);
        if ((lowpulse &gt;= MAXPULSE) &amp;&amp; (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 &lt; 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(");");
    }
}
</code></pre>

<p>This is the output:</p>

<blockquote>
  <p>Ready to decode IR!    </p>
  
  <p>Received:     </p>
  
  <p>OFF   ON<br>
  delayMicroseconds(34724);<br>
  pulseIR(3600);<br>
  delayMicroseconds(1800);<br>
  ......<br>
  delayMicroseconds(1340);<br>
  pulseIR(460);<br>
  delayMicroseconds(1360);<br>
  pulseIR(460);<br>
  Ready to decode IR!<br>
  Ready to decode IR!</p>
</blockquote>

<p>The last 2 rows appeared when I pressed the power button (twice).
The rows above appears when I press any other button.</p>

<p>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.</p>

<p>I tried resetting and re-uploading.</p>

<p>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.</p>
 313: <p>How high can <code>currentpulse</code> get before it is reset to zero? It is used an array index and if it gets larger than the (number of array elements-1), your code will write outside of the array.</p>

<p>Can the array be so far over-written that it grows into the stack area? That could definitely cause a reset, or reset-like behavior.</p>
