Let's Make Robots!

Entering in a Password

I have a problem with my code that involves you to enter in a numbered password. Right now I have 4 buttons that all do this:



  if (inputNum == 109){    // Arduino checks which button is pressed 


     x++;                      //Increments a space value

     a = a * 32;            // here is my system of recognizing the password. Each button does a random arithmetic thing the variable  

                                 a which is set at 1000. It works sometimes, but then some other number combinations work too.

       while(buttonUp){      // This is just to check if the person has released the button. So you dont get 5 numbers for one press.

       inputNum = analogRead(numberPad);

       if(inputNum <= 0){

         buttonUp = false;



    buttonUp = true;




My system is alittle flawed as you saw in my comment. I tried to use arrays but the problem is that I cant determine what place in the array the number is put into. That would involve a crazy amount of code that is unnecessary. If you dont get what i mean I'll explain it this way:

I have an array called passArray[] = {0, 0, 0, 0};

it has 4 numbers in it. Now when i press the one button i will assign the number one to the array. so the array will become now         {1, 0, 0, 0}

But if I dont in some crazy stuff like counting which array spot it got to and blah blah. When the person presses the second number, it will just replace the first. so lets say they press number to. The array would become {2, 0, 0, 0}. Unless you used variable to calculate which array value it is in. But even if you do, its kinda complicated. you have to increment x and have like 8 if statements to check what x is in order to place the number in the right place. The final product will have 9 buttons so i need to keep it simple.


I need a better system :P

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.


If I understand correctly each button does some kind of math operation and the 4 correct buttons pushed should always equal your "password" number? Why don`t you just remember the 4 buttons pushed, then check against the correct 4 buttons?

Arrays are very easy to use. Here is psuedo-code for filling an array with 4 numbers in the order in which they are pushed.

arrayIndex = 0
while(arrayIndex < 3)
    while(buttonInput == 0)
        buttonInput = waitForButtonInput()
    array(arrayIndex) = buttonInput

arrayIndex counts what position it is up to. When arrayIndex reaches 3 (actually 4 values) then it can continue with checking those numbers against the expected numbers of your password.

Never Mind. I figured it out. but the line

array(arrayIndex) = buttonInput

it says array cannot be used as a function even though i declared that array in the very top of my code. Do i have to so something else?

never mind found the problem, they were supposed to be [] not () arround arrayindex

Yep you got me. Hope it works for you.


Cool! I'll try this out tonight. Thanks!