Hi Guys, I have been around the barn on the this one and getting dizzy. Any insight would be appreciated.
I only want the if to trigger when the user simply hits enter (I.e. no other text) at the "Enter :" prompt. To my dismay, the if always triggers even if I enter text. My else feels so lonely. Uhg! I 'think' something is wrong with the way I'm trying to capture when the user simply hits enter "\r\n" at the "Enter : " prompt. I'm tried matching for '\r' and '\n', etc. In the serial monitor I've tried all four settings: no line ending, new line, carriage return, Both NL & CR. I'm just struggling.
String pedestalName;
void setup() {
Serial.begin(9600);
Serial.println("Enter : ");
while (Serial.available() == 0) {
}
while (Serial.available() > 0) {
pedestalName = Serial.readString(); // if string entered, else should trigger
Serial.print("pedestalName = "); // print out what is entered
Serial.println(pedestalName);
if (pedestalName = "\r\n") { // user simply hits enter on keyboard
char randomName[10];
itoa(millis(), randomName, 16); // https://fresh2refresh.com/c-programming/c-type-casting/c-itoa-function/
Serial.print("randomName = ");
Serial.println(randomName);
pedestalName = String(randomName);
}
else {
Serial.print("pedestalName = ");
Serial.println(pedestalName);
}
}
}
void loop() {
}