Basically I'm trying to output a string based upon a value in an array, the following code is what I have come up with to achieve my desired result, but I have a feeling that there is a better way to do it.
String day(int day) {
if (day == 1) return "Sunday";
if (day == 2) return "Monday";
if (day == 3) return "Tuesday";
if (day == 4) return "Wednesday";
if (day == 5) return "Thursday";
if (day == 6) return "Friday";
if (day == 7) return "Saturday";
else return "Undefined";
}
void setup() {
Serial.begin(57600);
while (!Serial);
Serial.println(day(1));
}
void loop() {
;
}
This prints "Sunday" in the Serial monitor
I would appreciate any input on how to optimize this code, thank you!