// Name: Choi Ka Ho
// No.: 240021155
// Class: EG114403/1D
// Program: Ex4_Q2
unsigned long previousMillis = 0;
const long interval = 5000; //5000ms
//Other operations can be performed simultaneously at an interval of
//5000 milliseconds.
void setup() {
Serial.begin(115600);
}
void loop() {
unsigned long currentMillis = millis();
//unsigned byte can represent values from 0 to 255,
// while signed byte can represent -128 to 127.
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
for (int k = 9; k > 0; k--) {
if (k % 2 != 0) { // Odd rows
for (int j = 1; j <= k; j++) {
Serial.print(j);
Serial.print(" ");
}
} else { // Even rows
for (int j = k; j > 0; j--) {
Serial.print(j);
Serial.print(" ");
}
}
Serial.println();
}
}
}