-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_device_welcome.ino
116 lines (94 loc) · 3.62 KB
/
new_device_welcome.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
This program is for new lab devices. It prints out a customizable message to serial.
Customize the device for the event and team by changing guestOrg and teamNumber.
The script output looks like this:
_ __ ____ ______
/ | / /___ _____________ / _/___/_ __/
/ |/ / __ \/ ___/ ___/ _ \ / // __ \/ /
/ /| / /_/ / / (__ ) __// // /_/ / /
/_/ |_/\____/_/ /____/\___/___/\____/_/
and the
INTERalliance
welcomes Student - Team 001 to TechOlympics 2024!
+-------------------------------------------------+
*/
#include <Arduino.h>
String guestOrg = "Student";
String teamNumber = "001";
// Separate each line with a \n.
String inputMessage = "and the\nINTERalliance\nwelcome " + guestOrg + " - Team " + teamNumber + " to TechOlympics 2024!";
#define SERIAL_BAUD 115200 // 115200 is the NorseIoT club standard
void centerAndPrintLine(String line, int maxLength) {
int lineLength = line.length();
int padding = (maxLength - lineLength) / 2;
// Center the line and print it
for (int j = 0; j < padding; j++) {
Serial.print(" ");
}
Serial.print(" "); // Two extra spaces on the left
Serial.print(line);
Serial.print(" "); // Two extra spaces on the right
Serial.println();
}
void setup() {
Serial.begin(SERIAL_BAUD);
Serial.println();
// Add a return character to the end of inputMessage
inputMessage += "\n";
// Calculate the maximum length for ASCII art
int maxArtLength = 0;
/* If the ASCII art contains a backslash, it must be escaped with a backslash!
Each line of the ASCII art should be a separate element in the array.
This program correctly handles larger or smaller ASCII artwork */
String asciiArt[] = {
" _ __ ____ ______",
" / | / /___ _____________ / _/___/_ __/",
" / |/ / __ \\/ ___/ ___/ _ \\ / // __ \\/ / ",
" / /| / /_/ / / (__ ) __// // /_/ / / ",
"/_/ |_/\\____/_/ /____/\\___/___/\\____/_/ "
};
// Calculate the maximum length for ASCII art
for (int i = 0; i < sizeof(asciiArt) / sizeof(asciiArt[0]); i++) {
int lineLength = asciiArt[i].length();
if (lineLength > maxArtLength) {
maxArtLength = lineLength;
}
}
int totalLines = 0; // Count the total number of lines in inputMessage
int maxMessageLength = 0;
int startIndex = 0;
for (int i = 0; i < inputMessage.length(); i++) {
if (inputMessage.charAt(i) == '\n' || i == inputMessage.length() - 1) {
totalLines++; // Increment the total line count
String line = inputMessage.substring(startIndex, i);
int currentLength = line.length();
if (currentLength > maxMessageLength) {
maxMessageLength = currentLength;
}
startIndex = i + 1;
}
}
// Calculate the total width for centering (the wider of the two)
int totalWidth = max(maxArtLength, maxMessageLength);
// Output centered ASCII art
for (int i = 0; i < sizeof(asciiArt) / sizeof(asciiArt[0]); i++) {
centerAndPrintLine(asciiArt[i], totalWidth);
}
// Output centered inputMessage
startIndex = 0;
for (int i = 0; i < totalLines; i++) {
int endIndex = inputMessage.indexOf('\n', startIndex);
String line = inputMessage.substring(startIndex, endIndex); // Extract each line
centerAndPrintLine(line, totalWidth);
startIndex = endIndex + 1;
}
// Print a line of dashes of the same width as the total width
Serial.print("+");
for (int j = 0; j < totalWidth + 4; j++) { // Add 4 extra spaces
Serial.print("-");
}
Serial.println("+");
}
void loop() {
// Your loop code (if any) goes here
}