-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathArduinoPCMonitor.ino
More file actions
167 lines (143 loc) · 3.93 KB
/
ArduinoPCMonitor.ino
File metadata and controls
167 lines (143 loc) · 3.93 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include <LiquidCrystal.h>
/* LCD settings */
#define CONTRAST 23
#define BACKLIGHT 28836
/* LCD pins */
#define PIN_CONTRAST 6
#define PIN_BACKLIGHT 9
#define PIN_RW 8
#define PIN_EN 7
#define PIN_D4 5
#define PIN_D5 4
#define PIN_D6 3
#define PIN_D7 2
/* Time until backlight is turned off if no update is received */
#define SCREEN_OFF_DELAY 10000
LiquidCrystal lcd(PIN_RW, PIN_EN, PIN_D4, PIN_D5, PIN_D6, PIN_D7);
String inputString = ""; // String for buffering the message
boolean stringComplete = false; // Indicates if the string is complete
int curFanChar = 0; // Current character of fan animation
unsigned long previousUpdate = 0; // Long to keep the time since last received message
boolean screenOn = true; // Indicates if the backlight is on or not
byte fanChar1[8] = {
0b00000,
0b00000,
0b01110,
0b10101,
0b11111,
0b10101,
0b01110,
0b00000
};
byte fanChar2[8] = {
0b00000,
0b00000,
0b01110,
0b11011,
0b10101,
0b11011,
0b01110,
0b00000
};
byte celsius[8] = {
0b01000,
0b10100,
0b01000,
0b00011,
0b00100,
0b00100,
0b00011,
0b00000
};
void printInitialLCDStuff() {
lcd.setCursor(0, 1);
lcd.print("GPU:");
lcd.setCursor(0, 2);
lcd.print("Fan:");
lcd.setCursor(0, 3);
lcd.print("Core/Mem:");
}
void serialEvent() {
while (Serial.available()) {
char inChar = (char)Serial.read();
inputString += inChar;
if (inChar == '|') {
stringComplete = true;
}
}
}
void setup() {
// Setup contrast and backlight
analogWrite(PIN_CONTRAST, CONTRAST);
analogWrite(PIN_BACKLIGHT, BACKLIGHT);
// Setup LCD
lcd.begin(20, 4);
printInitialLCDStuff();
// Setup serial
Serial.begin(9600);
inputString.reserve(200);
// Create the custom characters
lcd.createChar(0, fanChar1);
lcd.createChar(1, fanChar2);
lcd.createChar(2, celsius);
}
void loop() {
serialEvent();
if (stringComplete) {
if (!screenOn) {
// Turn on the backlight since we are updating the screen
analogWrite(PIN_BACKLIGHT, BACKLIGHT);
screenOn = true;
}
// CPU
int cpuStringStart = inputString.indexOf("C");
int cpuStringLimit = inputString.indexOf("|");
String cpuString = inputString.substring(cpuStringStart + 1, cpuStringLimit);
lcd.setCursor(0, 0);
lcd.print(cpuString);
// GPU 1
int gpu1StringStart = inputString.indexOf("G", cpuStringLimit);
int gpu1StringLimit = inputString.indexOf("|", gpu1StringStart);
String gpu1String = inputString.substring(gpu1StringStart + 1, gpu1StringLimit);
lcd.setCursor(5, 1);
lcd.print(gpu1String);
// GPU 2
int gpu2StringStart = inputString.indexOf("F", gpu1StringLimit);
int gpu2StringLimit = inputString.indexOf("|", gpu2StringStart);
String gpu2String = inputString.substring(gpu2StringStart + 1, gpu2StringLimit);
lcd.setCursor(5, 2);
lcd.print(gpu2String);
// GPU 3
int gpu3StringStart = inputString.indexOf("g", gpu2StringLimit);
int gpu3StringLimit = inputString.indexOf("|", gpu3StringStart);
String gpu3String = inputString.substring(gpu3StringStart + 1, gpu3StringLimit);
lcd.setCursor(10, 3);
lcd.print(gpu3String);
// Print fan animation
lcd.setCursor(10, 2);
lcd.write((uint8_t)curFanChar);
curFanChar = !curFanChar;
// Print celsius symbol in the appropriate positions
lcd.setCursor(12, 1);
lcd.write((uint8_t)2);
// CPU core temps celsius symbols
lcd.setCursor(7, 0);
lcd.write((uint8_t)2);
lcd.setCursor(11, 0);
lcd.write((uint8_t)2);
lcd.setCursor(15, 0);
lcd.write((uint8_t)2);
lcd.setCursor(19, 0);
lcd.write((uint8_t)2);
inputString = "";
stringComplete = false;
previousUpdate = millis();
} else {
// Check if we should turn off the backlight
if (millis() > previousUpdate + SCREEN_OFF_DELAY && screenOn) {
// Turn off the backlight
screenOn = false;
analogWrite(PIN_BACKLIGHT, LOW);
}
}
}