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
lcd.print("1");
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