void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println("Input 1 and press Enter:");
while (Serial.available() == 0) {} // Wait for user to inpu data
String teststr = Serial.readString(); // Read the data
teststr.trim(); // Remove any \r \n whitespace at the end of the String
if (teststr == "1")
{
Serial.println("Input any character to continue:");
while (Serial.available() == 0) {} // Wait
String inputChar = Serial.readString(); // Read
inputChar.trim(); // Remove
if (inputChar)
{
String teststr2; //declear the word user will input
bool validColor = false; //is the input word a valid color? this bool variable is a Indicator falg in the entrancy gat of while loop below.
//give it a inital false so that program can enter the while loop
while(!validColor) //if the word is not color, come back to here, otherwise the valid color will allow program doing process then go back to main while loop
{
Serial.println("Select the color of the part (Red, Green, Blue, Orange):");
//Serial.println(Serial.readString());
while (Serial.available() == 0) {} //Wait
teststr2 = Serial.readString(); //Read
teststr2.trim(); //Remove
teststr2.toLowerCase(); //user might input RED, Red, REd, even rEd! bcs they are fkin stupid
//turn all characters to lowcase to elimate Misinterpretation
if (teststr2 == "red")
{
Serial.println("The red part has been picked and placed in the red bin.\n");
validColor = true; //sucess of input color will make program wouldn't come back to this while when we set validColor is true
}
else if (teststr2 == "green")
{
Serial.println("The green part has been picked and placed in the green bin.\n");
validColor = true;
}
else if (teststr2 == "blue")
{
Serial.println("The blue part has been picked and placed in the blue bin.\n");
validColor = true;
}
else if (teststr2 == "orange")
{
Serial.println("The orange part has been picked and placed in the orange bin.\n");
validColor = true;
}
else
{
Serial.println("Error: Invalid color. Please try again.\n");
validColor = false;
}
}
}
}
else
{
Serial.println("Invalid input. Try again.\n");
}
}