// Program: 1C Ex3 Q1 Chan Tai Ming.ino
/*
Exercise 3
Experience with Serial input,
select "Newline" option for Serial Monitor
type a character within the upmost bar, then press ENTER
Learn to use if else
*/
void setup()
{
// Initialize serial and wait for port to open
Serial.begin(115200);
while (!Serial)
{
// Wait for serial port to connect, needed for native USB port only
}
Serial.println("Please input a character:");
}
void loop()
{
char a;
while (Serial.available())
{
a = Serial.read();
// delay(10); // comment out when using ESP32
// serial data comes in very slowly compared to
// how fast the Arduino runs
Serial.read(); // the second read is the new line \n
// if ((a >= '0') && ( a <= '9'))
// {
// Serial.print("You have input a digit: ");
// // Serial.println(a);
// // Serial.println();
// // Serial.println("Please input a character:");
// }
// else if ((a >= 'A') && ( a <= 'Z')) {
// Serial.print("You have input an uppercase: ");
// // Serial.println(a);
// // Serial.println();
// // Serial.println("Please input a character:");
// }
// else if ((a >= 'a') && ( a <= 'z')) {
// Serial.print("You have input a lowercase: ");
// // Serial.println(a);
// // Serial.println();
// // Serial.println("Please input a character:");
// }
// else {
// Serial.print("You have input an other: ");
// // Serial.println(a);
// // Serial.println();
// // Serial.println("Please input a character:");
// }
switch (a) {
// case 48 ... 57: // Duplicated !!
// case '0' ... '9': Serial.print("You have input a digit: ");
case '0' ... 57: Serial.print("You have input a digit: ");
break;
case 65 ... 90: Serial.print("You have input an uppercase: ");
break;
case 97 ... 122: Serial.print("You have input a lowercase: ");
break;
default: Serial.print("You have input an other: ");
break;
}
Serial.println(a);
Serial.println();
Serial.println("Please input a character:");
}
}