-
Notifications
You must be signed in to change notification settings - Fork 1
/
MCServerStatus.ino
66 lines (52 loc) · 1.28 KB
/
MCServerStatus.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
///////////////////////////////
// MCServerStatus Arduino //
// THIS IS NEW UNTESTED CODE //
// by jackwilsdon //
///////////////////////////////
// Online & Offline LED Pins
int onlineLED = 6;
int offlineLED = 7;
// Incoming data holder
int incomingByte = 0;
void setup() {
// Set LEDS to output
pinMode(onlineLED, OUTPUT);
pinMode(offlineLED, OUTPUT);
// Configure serial
Serial.begin(9600);
// Set server to offline
digitalWrite(onlineLED, LOW);
digitalWrite(offlineLED, HIGH);
}
boolean isOnline(int in) {
// If input code is 49 (1)
if (in == 49) {
return true; // Server is online
} else {
return false; // Server is offline
}
}
void setStatus(int stat) {
// If status is 1 (server is online)
if (stat == 1) {
digitalWrite(onlineLED, HIGH); // Turn online LED on
digitalWrite(offlineLED, LOW); // Turn offline LED off
} else {
// The server is offline
digitalWrite(onlineLED, HIGH); // Turn online LED off
digitalWrite(offlineLED, LOW); // Turn offline LED on
}
}
void loop() {
// If data is being sent
if (Serial.available() > 0) {
// Read the data
incomingByte = Serial.read();
// Check if server is online
if (isOnline(incomingByte)) {
setStatus(1); // Set server status
} else {
setStatus(0); // Set server status
}
}
}