I'm trying to write a program, which will allow me to enter a password using the serial monitor, and compare it to a pre-entered password. Just comparing the password i enter letter by letter to the pre-entered one. It should be simple enough, but it simply isn't working. Still new to Arduino, and could use some help. Am I missing something?
I think its better if you save all the serial data in one string, and then compare the data recieved with the password saved using strcmp, instead of doing it char by char
After a few experiences with your program I see that is not completed correct.
If you place here a ';' you always do the following block, and is the same that don't have the if at all:
if(index < 8);
I did not understand the ' mismatch == 0' part of the while condition:
while(Serial.available() > 0 && mismatch == 0)
with this part if you get a mismatch you will stop to reading the characters that come from the serial and you will never see the correct password.
The reason I'm using mismatch == 0 in the while condition, is so that if any of the inserted characters is wrong, the program will say that the password is wrong without having to read the rest of it. And thanks for the observation about the if statement! Embarrassing, but I had totally overlooked that...But even after correcting the if thing, I still cant figure out why the program is breaking out of the while loop!!
Look at the Arduino code in this demo for a system that reliably receives data over a serial connection. It works with the Serial Monitor as well as with Python.
hephestus:
The reason I'm using mismatch == 0 in the while condition, is so that if any of the inserted characters is wrong, the program will say that the password is wrong without having to read the rest of it.
(...)