Serial.read() will return the ASCII characters from the serial input, not numbers so when you type say 5 you will receive the number 53 or in hex 0x35. It is only half a byte or a nibble, that is 4 bits.
Then you need to assemble these nibbles into a byte by using shift and the bitwise OR operation, only then can you compare it to a byte stored in EEPROM.
hello guys... actually i am a team member of taha...
if(Serial.available()){
input += (int)Serial.read();
delay(30);
//if(input =="taha");
Serial.println("The unique number you entered is correct");
}
by the way here is where i have problem in program...
wen the program creates a random number and saves it in EEPROM.
next step i need to give a serial monitor input ans compare that to the EEPROM data.. what shud i do...??? plzzz helppp
for (int i = 0; i < EEsize; i++)
{
randNumber=random(255);
Serial.println(randNumber);
EEPROM.write(i, randNumber);
}
Serial.println();
for (int a=0; a<EEsize; a++)
{
taha = EEPROM.read(a);
Serial.print("EEPROM position: ");
Serial.print(a);
Serial.print(" contains ");
Serial.println(taha);
}
{
if(Serial.available()){
input += (int)Serial.read();
delay(30);
if(input=="taha");
Serial.println("The unique number you entered is correct");
}
in this program the random number function creates a random number upto 255, save dat to the EEPROM position and display it in serial monitor.
and that random number should be given as input in serial monitor and compared to the EEPROM position.
i tried it alot but only singlr digit is possible. i need to get output for three digit comparision..
Is there some good
reason that your code
wanders all over the
place?
There was a lot of effort put
into the Tools + Auto Format
menu item to take
care of that
problem.
input += (int)Serial.read();
I'm sure that there is some good reason why you are casting an int to an int. I can't wait to hear it,
Is taha a byte or a string? In the second for loop, you are using taha as a byte. In the third, you are comparing the serial input that you have received so far to the string "taha".