IR remote unstable button numbers Question

Is there a reason for unstable button numbers of an IR remote?

Desciption

I wrote a remote class where I identify the pressed number of the remote to set states. But however I get never the same number of the pressed key.

For example I press the number '1' and on the serial interface shows this:

3588650484
2740290906
3148594742
689746115
2396927248
2934053595
4294967295
3876827360


And it should look like this:

16724175 // Button 1
4294967295
16724175 // Button 1
16724175 // Button 1
16724175 // Button 1
16724175 // Button 1


Hardware

I am using an arduino UNO board and the standart remote of the starter kit. There is no name just 'SPECIAL FOR MP3'.

Some more infos

Ok, in my first project I used the code from Noreddine Kessa(Example Project) which works fine. Next I copied some code in my new class 'IRControl.cpp' ( you can see below). Then I created an object IRControl in the main.cpp and run the menu() in the loop.

h-File:

/*
 * IRControl.h
 *
 *  Created on: 04.04.2016
 *      Author: David
 */

#ifndef IRCONTROL_H_
#define IRCONTROL_H_

//Remote Defines
#define buttonON 16753245
#define buttonMode 16736925
#define buttonSoundOff 16769565
#define buttonPlayStop 16743045
#define buttonTrackBack 16712445
#define buttonTrackForward 16761405
#define buttonEQ 16769055
#define buttonMinus 16754775
#define buttonPlus 16748655
#define button0 16738455
#define buttonRepeat 16750695
#define buttonJSD 16756815
#define button1 16724175
#define button2 16718055
#define button3 16743045
#define button4 16716015
#define button5 16726215
#define button6 16734885
#define button7 16728765
#define button8 16730805

#include "IRremote.h"
#include "wiring_private.h"

enum zustaende{Motor1, Motor2, Motor3, Sleep};
extern int zustand;

class IRControl {
private:
    IRrecv *irrecv;
    decode_results remoteValue;
public:
    IRControl(int RECV_PIN);
    virtual ~IRControl();
    void menu();
};

#endif /* IRCONTROL_H_ */


cpp-File:

* IRControl.cpp
 *
 *  Created on: 04.04.2016
 *      Author: David
 */

#include "IRControl.h"

IRControl::IRControl(int RECV_PIN) {
    // TODO Auto-generated constructor stub
    irrecv = new IRrecv(RECV_PIN);
    pinMode(RECV_PIN , INPUT);
    irrecv-&gt;enableIRIn();
}

IRControl::~IRControl() {
    // TODO Auto-generated destructor stub
    delete irrecv;
}

void IRControl::menu() {
    if (irrecv-&gt;decode(&amp;remoteValue)) {
        //lReceived = remoteValue.value ;
        Serial.println(remoteValue.value);
        /*
        switch(remoteValue.value)
                {
                case button1:
                    zustand = Motor1;
                    //digitalWrite (LED1, HIGH); // for control
                    break;

                case button2:
                    zustand = Motor2;
                    //digitalWrite (LED2, HIGH);
                    break;
                case button3:
                    zustand = Motor3;
                    //digitalWrite (LED3, HIGH);
                    break;

                case button0:
                    zustand = Sleep;
                    break;

                default: break;
                }
                */
        irrecv-&gt;resume(); // Receive the next value
      }
}


Where the problem could be

I think there could be a problem with the IRrecv *irrecv;. But i'm not sure.

Thanks for your help
Please post the code where you call the library. In particular where do you make an instance of IRControl?

I am guessing you are doing it at global scope which means you are probably running into the C++ static initialization order fiasco.

What it is: http://www.parashift.com/c++-faq/static-init-order.html

How to prevent it: http://www.parashift.com/c++-faq/static-init-order-on-first-use.html

To prevent this, you should not be doing this in the class constructor:

irrecv = new IRrecv(RECV_PIN);
pinMode(RECV_PIN , INPUT);
irrecv-&gt;enableIRIn();


Instead, make a begin function (like most Arduino classes do) and call that from setup.