samedi 18 avril 2015

Combined loops not working in Arduino

I have an arduino code which is doing tasks like this:



while (a=='A')
{
//do the task A
}

while (a=='B')
{
//do the task B
}


These loop run correctly when they are run separately. But the problem comes when I try to combine both loops i.e.



void loop ()
{
while (a=='A')
{
//do the task A
}

while (a=='B')
{
//do the task B
}
}


Below is the code in full details:



void loop()
{
////// admin
Serial.println("A or B");
delay(500);
char a = userinput();
delay(500);
while(a== 'A'){
Serial.println("Type Your Starting ID Number...");
while(1 ){
while (Serial.available()==false);
char e = Serial.read();
if(isdigit(e)==false) break;
startid = (startid*10)+(e - 48);
}
if(startid<=endid){
for(pageid=startid; pageid<=endid; pageid++)
{
Serial.print("Your Biometric ID # is ");
Serial.println(pageid);
delay(2000);
fingerenrollment(pageid);
delay(2000);
if(pageid == endid){
Serial.println("......Memory Is Full....");
while(1);
}
}
}
else{
Serial.println("Wrong Entry.......Please Reset Your Device.....");
while(1);
}
}
////// user
while(a=='B'){
lcd.print("WELCOME TO iPoll");
delay(2000);
lcd.clear();
lcd.print("Place Your Thumb");
delay(2000);
lcd.clear();
tempid = '\0';
Serial.println("Place your Thumb For Authentication");
delay(500);
while(true){
ID = fingerauthentication();
delay(500);
if(tempid != '\0') break;
}
delay(100);
resp = userinput();
delay(100);
lcd.clear();
datatrans(ID, resp);
}
}


If you need any more help, I am here. Just comment.


Aucun commentaire:

Enregistrer un commentaire