-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
56 lines (48 loc) · 805 Bytes
/
Copy pathmain.cpp
File metadata and controls
56 lines (48 loc) · 805 Bytes
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
// Do not remove the include below
#include "main.h"
void setup() {
initLedBut();
initClock();
Serial.begin(115200);
Serial.println("Clock v1.0");
}
#define CMD_SIZE 10
char *getMsg(void) {
int c;
int static index;
char static cmd[CMD_SIZE+1];
if ((c = Serial.read()) != -1) {
if (index && ((char) c == '\r')) {
cmd[index] = '\0';
index = 0;
return cmd;
}
else {
if (index < CMD_SIZE)
cmd[index++] = (char) c;
return 0;
}
}
return 0;
}
void procMsg(char *msg) {
switch(msg[0]) {
case 'l':
cmdLed(msg);
break;
case 'b':
cmdBut(msg);
break;
case 'c':
cmdClock(msg);
break;
}
}
void loop() {
char *msg;
if ((msg = getMsg()) != 0) {
procMsg(msg);
}
procBut();
procClock();
}