Newbie - Getting the next value pressed by the user on the IR Remote control.

Hi guys!

I need to trigger a relay after the user press the 5 key, but before starting the relay the user must confirm a password.

My idea is to save in a vector the user-pressed numbers.

My problem is when he presses the 5 key… when he press the 5 key the frist time, that key should’t be inserted into the vector “teste”, i need the next number press by the user, so i can add into the vector and compare with the password already save in the vector “password”

void setup()
{
  lcd.begin(16, 2); 
  pinMode (rele1, OUTPUT);
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  
  int tecla1= 0xE12440BF;
  int tecla2= 0xE12428D7;
  int tecla3= 0xE1246897;
  int tecla4= 0xE124B847;  
  int tecla5= 0xE124F00F;
  int tecla6= 0xE1249867;
  int tecla7= 0xE1247887;
  int tecla8= 0xE124B04F;
  int tecla9= 0xE124F807;
  int number= 0xE124E817;
  int cont =0;


 int password [1] = {0xE12440BF}; 
 int teste [1];

  


  if (irrecv.decode(&results)) {
  
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
    delay (2000);
    armazenavalor = (results.value);
    
  }  
      if (results.value == 0xE12440BF){
      
     
      lcd.clear();                      
      lcd.print("Insirir a senha  :");
      lcd.setCursor(0,1);   
      lcd.print("# para confirmar"); 
      
      
    for (int i=0;i<=1;i++){
        teste [i] = results.value; 
     }
    
        
       for (int i=0;i<1;i++){  // compare
         if (teste[i] == password [i]){
           lcd.clear();                           
           lcd.print("password correct :");  
         }else{
           lcd.clear();                           
           lcd.print("password wrong :");  
         } 
       
     
   }
      }


  }
}

groundfungus: An int holds 2 bytes, not 4.

Any suggestion how i should declare?

I'm newbie with Arduino, sorry for the dumb questions =/

Any suggestion how i should declare?

The type should be long, not int.

 int password [1] = {0xE12440BF}; 
 int teste [1];

One element arrays are pretty useless.

    for (int i=0;i<=0;i++){
        teste [i] = results.value; 
     }

Starting with i equal to 0, while i is less than or equal to 0, do this, then increment i by 1. How many times is that loop going to iterate?

PaulS:
The type should be long, not int.

 int password [1] = {0xE12440BF}; 

int teste [1];



One element arrays are pretty useless.

Forgot to mention, the password will have 4 digits, the vector has only one position for testing.

    for (int i=0;i<=0;i++){

teste [i] = results.value;
    }



Starting with i equal to 0, while i is less than or equal to 0, do this, then increment i by 1. How many times is that loop going to iterate?

Yep that vector index was wrong, sorry.

but the problem remain, how I discart the first number entered by the user, and only add the second one in the vector?

but the problem remain, how I discart the first number entered by the user, and only add the second one in the vector?

You have some state - user has not entered the first number. You have another state - user has entered the first number. You have another state - user has entered all the numbers.

Clearly, in one state you store data. In another state, you don't. In another state, you use the data that has been stored.

Can you match the states with the actions? Can you determine a way to know which state you are in?

Not sure I can help much with the IR issue, but from a code point:

You seem to have an additional closing bracket.

There are a few non declared variables. But perhaps these are globals not copied in your example?

As for skipping the first key press, currently it looks like your getting the key press each frame, and storing it in the first element of your teste array.

If I was goign to attempt this, I would probably code a simple state engine, which proceeds to a PASSWORD_INPUT state once the 5 key has been pressed. Then inside this state keep use your array as a rolling buffer as key strokes come in.

PaulS: You have some state - user has not entered the first number. You have another state - user has entered the first number. You have another state - user has entered all the numbers.

Clearly, in one state you store data. In another state, you don't. In another state, you use the data that has been stored.

Can you match the states with the actions? Can you determine a way to know which state you are in?

I'm trying to find a logic to prevent that the same selected key used to enter the password menu is added to the vector at same time, because this key will only serve to show the user, that he can registrated the password.

im think there's a way to to determine that the user pressed the 5 key, and only add the next key pressed by the user to the vector.

but I still can't understand how =/

Thx to trying to help! =D

tammytam: If I was goign to attempt this, I would probably code a simple state engine, which proceeds to a PASSWORD_INPUT state once the 5 key has been pressed. Then inside this state keep use your array as a rolling buffer as key strokes come in.

could you detail a little more that part?

Thx to trying to help! =D