I'm trying to create a lock
And while making the code I've encountered 2 annoying issues:
- A Serial.println() function from a different function runs without being called
- every time the same Serial.println is being called, it removes the first letter of the string for some reason
These are the 2 problematic functions, the first one is the getCodeInput() function - which triggers the Serial.println() function from a different function INSTEAD OF THE ONE IT ACTUALLY NEEDS TO PRINT
void getCodeInput(int passLength, int amountOfNums, int* userInput)
{
int i = 0;
int aButtonPressed = HIGH;
for(i = 0; i < AMOUNT_OF_NUMBERS; i++)
{
aButtonPressed = HIGH;
aButtonPressed = digitalRead(numKeys[i]); //Checking on each number if it has been pressed, if yes - run the rest of the code
if (aButtonPressed == LOW)
{
if (count < PASSWORD_LENGTH)
{
userInput[count] = i;
count++;
Serial.println(count + "^");
}
break;
}
}
}
The second one is getNewPassword, which has the problematic Serial.println() command (the one that says "CHANGE PASS"), each time the first function calls it - it runs the Serial.println() command and each time it removes the first letter of the string
In the first time the first function runs after a user's input reset - it does not print anything upon getting an input (and it needs to print the input thst the user entered so far) - not even the "CHANGE PASS" string
void getNewPassword(int passLength, int* userInput, int numCount, int* oldPassword)
{
resetInput(userInput, PASSWORD_LENGTH);
Serial.print("CHANGE PASS\n");
while (count != passLength)
{
getCodeInput(passLength, numCount, userInput);
delay(1000);
}
changePass(oldPassword, userInput, passLength);
printArray(oldPassword, PASSWORD_LENGTH);
}
Here is an output example so you'll be able to see the issue (-1 is a placeholder for not having anything inserted there)
CHANGE PASS
HANGE PASS
ANGE PASS
1101
FAILURE
CHANGE PASS
HANGE PASS
ANGE PASS
1233
FAILURE
Extra info:
- The only time that the getNewPassword is being called is when the user enters a specific sequence of number AFTER getting the normal password correctly, and here the Serial.println in the function is being printed because of the getCodeInput function.
-The arduino board is Arduino Uno.
-The getCodeInput function is being called inside the getNewPassword function, but I do not call it upon a code fail.
-The code writes "FAILURE" every time the password entered was incorrect - not the sequence to change the password
Please help me, thanks!