-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmacros.h
48 lines (41 loc) · 2.08 KB
/
macros.h
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
#define WAITFORINPUT(){ \
while(!Serial.available()){}; \
while(Serial.available()){ \
Serial.read(); \
}; \
} \
/* macros to shift array. Parameters are inclusive. For example:
int array[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
ARRAYSHIFTUP(array, 2, 6) => { 1, 2, 3, 3, 4, 5, 6, 7, 9, 10 };
ARRAYSHIFTDOWN(array, 2, 6) => { 1, 3, 4, 5, 6, 7, 7, 8, 9, 10 }; */
#define ARRAYSHIFTUP(a, lower, upper){ \
if (lower == 0){ \
for (int q = lower; q < upper; q++){ \
*(a + q) = *(a + q + 1); } \
} else{ \
for (int q = lower - 1; q < upper; q++){ \
*(a + q) = *(a + q + 1); }}} \
#define ARRAYSHIFTDOWN(a, lower, upper){ \
if (upper == (sizeof(a)/sizeof(a[0])) - 1){ \
for (int q = upper - 1; q >= lower; q--){ \
*(a + q + 1) = *(a + q); } \
} else{ \
for (int q = upper; q >= lower; q--){ \
*(a + q + 1) = *(a + q); }}} \
#define ARRAYAVERAGE(a, out){ \
float sum = 0; \
for (int i = 0; i < sizeof(a)/sizeof(a[0]); i++){ \
sum += a[i];} \
out = sum/(sizeof(a)/sizeof(a[0]));} \
#define CLEARARRAY(a){ \
for (int q = 0; q < sizeof(a)/sizeof(a[0]); q++){ \
a[q] = 0; }} \
#define CLEARSERIAL(){ \
while (Serial.available()){ \
Serial.read(); }} \
#define PRINTARRAY(a){ \
Serial.print('{'); \
for (int i = 0; i < sizeof(a)/sizeof(a[0]); i++){ \
Serial.print(a[i]); \
Serial.print('\t'); } \
Serial.println('}'); } \