im trying to make a security system were you have to have # before the password to for the arduino to respond e.g if the password is pi you would have to write #pi in the serial monitor fro the arduino to actually respond. if the password is pi and i type in the serial monitor #pi the arduino is supposed to respond with acess.# then acess.a then, acess.b and then acess granted but so far it only responds with acess.# although im tyinping in #pi could someone plz help me.
ascii
= 35
p = 112
i = 105
code
int valhash = 0; // password initializer
int vala = 0;// first char in password
int valb = 0;// second char in password
void setup()
{
Serial.begin(9600);
}
void loop()
{
while( Serial.available()==0);
int val = Serial.read();
int vali= Serial.read(); // initialze pasword value
if(vali == 35)
{
if (val == 35) // if # key is pressed
{
Serial.println("acess.#");
valhash = 1;
Serial.println( valhash);
}
else
{
valhash == 0;
}
}
if(vali == 35)
{
if (val == 112) // p is pressed
{
Serial.println("acess.a");
vala = 1;
Serial.println( vala);
}
else
{
vala == 0;
}
} // end of p loop
if(vali == 35)
{
if ( val == 105)// i is pressed
{
Serial.println("acess.b");
valb = 1;
Serial.println( valb);
}
else
{
valb == 0;
}
} //end of i loop
else if ( vali == 35) // acess denied
{
Serial.println("acess denied");
}
if (vala == 1 && valb == 1 && valhash)
{
Serial.println( "acess granted");
}
// end of pass granted loop
if ( val >= 0)// resets values of val
{
vala == 0;
valb == 0;
valhash == 0;
}
}