Hello AACs ..
I am totally new to Arduino, just bear with me please ...
I was trying to code a simple arduino game that can read the resultant number from the player's mind, simple and pure mathematics which will always yield the number "3". Problem is, I would like to hang the code until the user types "ok" then presses ENTER in the serial monitor window, but after the program reaches the line :
and the user types "ok" and presses enter, the program keeps running and the
code is not functional anymore and the program wont hang to wait for an entry and the program keeps looping afterwards!
What's going on? what did i do wrong?
I am totally new to Arduino, just bear with me please ...
I was trying to code a simple arduino game that can read the resultant number from the player's mind, simple and pure mathematics which will always yield the number "3". Problem is, I would like to hang the code until the user types "ok" then presses ENTER in the serial monitor window, but after the program reaches the line :
Code:
Serial.println("Type ""ok"" and press ENTER when you've already choosen a number . . . ");
Code:
while (Serial.available()==0) { }
Code:
void loop() {
Serial.println("Choose any number from 1 to 10");
delay(7000);
Serial.println(" ");
Serial.println("Type ""ok"" and press ENTER when you've already choosen a number . . . ");
while (Serial.available()==0) { }
Serial.println("Now .. Multiply your number by 5");
delay(5000);
Serial.println("Type ""ok"" and press ENTER when you know the result");
while (Serial.available()==0) ; {
}
Serial.println("Ok .. Divide your current number by the original number then type ""ok"" and press ENTER when ready");
while (Serial.available()==0) {
}
Serial.println("Now subtract 2 from the current number then type ""ok"" and press ENTER");
while(Serial.available()==0) {
}
delay(3000);
Serial.println("You've got a number right now");
delay(2000);
Serial.println("But .. It is inside your mind, in the Damagh el Kachaa of yours");
delay(2000);
Serial.println("Reading your mind now!! ... ");
delay(1000);
Serial.println("PROCESSING . . . . . . . . . . .");
for (int i=1; i<=3; i=i+1) // i= the for loop execution times
{
digitalWrite(RLEDpin,HIGH);
delay(250);
digitalWrite(RLEDpin,LOW);
digitalWrite(BLEDpin,HIGH);
delay(250);
digitalWrite(BLEDpin,LOW);
digitalWrite(RLEDpin,HIGH);
delay(250);
} // End of "for" code
digitalWrite(BLEDpin,LOW);
digitalWrite(RLEDpin,LOW);
Serial.println("Ok .. Now I know it ya khabeel");
delay(2000);
Serial.print("It is ");
delay(2000);
Serial.print("The number 3 ");
Serial.print(" ");
Serial.print(" ");
Serial.print(" ");
Serial.print(" ");
}
What's going on? what did i do wrong?
Last edited: