-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathStreamingExample.ino
More file actions
52 lines (41 loc) · 1.78 KB
/
Copy pathStreamingExample.ino
File metadata and controls
52 lines (41 loc) · 1.78 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
#include <Streaming.h>
const long BAUD = 115200;
const int lettera = 'A';
const int month = 4, day = 17, year = 2009;
const int hour = 8, minute = 20, second = 3;
const float pi = 3.14159;
const char raw_status[] = {'O', 'K', '!'};
const long LOOP_DELAY = 1000;
void setup() { Serial.begin(BAUD); }
void loop() {
Serial << "This is an example of the new streaming" << endl;
Serial << "library. This allows you to print variables" << endl;
Serial << "and strings without having to type line after" << endl;
Serial << "line of Serial.print() calls. Examples: " << endl;
Serial << "A is " << lettera << "." << endl;
Serial << "The current date is " << day << "-" << month << "-" << year << "."
<< endl;
Serial << "You can use modifiers too, for example:" << endl;
Serial << _BYTE(lettera) << " is " << _HEX(lettera) << " in hex. " << endl;
Serial << endl;
Serial << "In library v6, you also get" << endl;
Serial << "Padding [" << _PAD(10, '*') << "]" << endl;
Serial << "Width specification [" << _WIDTH(10, 5) << "]" << endl;
Serial << "Leading zeros [" << _WIDTHZ(month, 2) << "]" << endl;
Serial << _FMT("Format strings for stuff like dates and times %/%/% %:%:%",
_WIDTHZ(day, 2), _WIDTHZ(month, 2), year, _WIDTHZ(hour, 2),
_WIDTHZ(minute, 2), _WIDTHZ(second, 2))
<< endl;
Serial << _FMT(F("To reduce your % size, these % can be in %"), F("sketch"),
F("constants"), F("PROGMEM"))
<< endl;
Serial << endl;
Serial << "pi to 3 digits = " << _FLOAT(pi, 3) << endl;
Serial << "status = " << _BYTES(raw_status, sizeof(raw_status)) << endl;
// comma separator
int f = 11;
Serial << "Data: " << 1, 3, 5, 7, 9, f;
Serial << endl;
Serial << "comma separator works!" << endl;
delay(LOOP_DELAY);
}