-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathutility.cpp
More file actions
85 lines (74 loc) · 1.96 KB
/
Copy pathutility.cpp
File metadata and controls
85 lines (74 loc) · 1.96 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
/*****************************************
* RemoteArDuino (RAD) Gate
* (c) Danny Frencham 2017
*****************************************/
#include "utility.h"
// Prints a string to serial
// print_string string to print
void serial_print(const char* print_string) {
if (Serial) {
Serial.print("[");
Serial.print(millis());
Serial.print("] ");
Serial.print(print_string);
Serial.print("\n");
}
}
// Prints a named value to serial
// print_string description
// print_val value
void serial_print_val(const char* print_string, unsigned long print_val) {
if (Serial) {
Serial.print("[");
Serial.print(millis());
Serial.print("] ");
Serial.print(print_string);
Serial.print(" ");
Serial.print(print_val);
Serial.print("\n");
}
}
// LED light chase
// c colour
void chase(Adafruit_NeoPixel strip, uint32_t c) {
for(uint16_t i=0; i<strip.numPixels()+4; i++) {
strip.setPixelColor(i , c); // Draw new pixel
strip.setPixelColor(i-4, 0); // Erase pixel a few steps back
strip.show();
delay(50);
}
}
// clever print function
//https://gist.github.com/EleotleCram/eb586037e2976a8d9884
int aprintf(char *str, ...) {
int i, j, count = 0;
va_list argv;
va_start(argv, str);
for(i = 0, j = 0; str[i] != '\0'; i++) {
if (str[i] == '%') {
count++;
Serial.write(reinterpret_cast<const uint8_t*>(str+j), i-j);
switch (str[++i]) {
case 'd': Serial.print(va_arg(argv, int));
break;
case 'l': Serial.print(va_arg(argv, long));
break;
case 'f': Serial.print(va_arg(argv, double));
break;
case 'c': Serial.print((char) va_arg(argv, int));
break;
case 's': Serial.print(va_arg(argv, char *));
break;
case '%': Serial.print("%");
break;
default:;
};
j = i+1;
}
};
va_end(argv);
if(i > j) {
Serial.write(reinterpret_cast<const uint8_t*>(str+j), i-j);
}
return count;
}