You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+33-3Lines changed: 33 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,8 +24,8 @@ void setup() {
24
24
}
25
25
```
26
26
27
-
## Using cin an cout
28
-
When you include this header file you automatically get cin and cout based on Serial. There isn't yet a way to select you own device at runtime. Using cin and cout is
27
+
## Using ```cin``` an ```cout```
28
+
When you include this header file you automatically get cin and cout based on ```Serial```. See below for how to specify your own device. Here's an example sketch using ```cin``` and ```cout``` .
29
29
30
30
```c++
31
31
#include<ArduinoSTL.h>
@@ -47,10 +47,40 @@ void loop() {
47
47
}
48
48
}
49
49
```
50
+
## Changing the Serial Port
51
+
You can change what serial port that ```cin```, ```cout``` and ```printf()``` use. You can use built-in serial ports (e.g. ```Serial1``` on Leonardo) or you can use software serial ports that implement ```Stream```.
52
+
53
+
### Using a Built-in Port
54
+
In ```src/ArduinoSTL.cpp``` change the value of ```ARDUINOSTL_DEFAULT_SERIAL```. Leave the other defaults uncommented.
55
+
56
+
### Using a SoftwareSerial port.
57
+
Set ```ARDUINO_DEFAULT_SERAL``` to ```NULL```. Comment out the other defaults.
58
+
59
+
Here's an example sketch that uses SofwareSerial:
60
+
61
+
```c++
62
+
#include<ArduinoSTL.h>
63
+
#include<SoftwareSerial.h>
64
+
65
+
SoftwareSerial mySerial(0, 1);
66
+
67
+
namespace std {
68
+
ohserialstream cout(mySerial);
69
+
ihserialstream cin(mySerial);
70
+
}
71
+
72
+
void setup() {
73
+
mySerial.begin(9600);
74
+
ArduinoSTL_Serial.connect(mySerial);
75
+
}
76
+
```
77
+
78
+
## Avoiding Instantiation of ```cin``` and ```cout```
79
+
Comment out ```ARDUINOSTL_DEFAULT_CIN_COUT``` and nothing will be instantiated. You must comment out this flag if you intend to select a non-default serial port. There's no appreciable overhead for using ```printf()``` so you cannot currently avoid initializaing it.
50
80
51
81
## Known Issues
52
82
53
-
Printing of floats and doubles using cout ignores format specifiers.
83
+
Printing of floats and doubles using ```cout``` ignores format specifiers.
54
84
55
85
uClibc seems to be fairly complete. Strings and vectors both work, even with the limited amount of heap available to Arduino. The uClibc++ status page can be found here:
sentence=A port of uClibc++ packaged as an Arduino library.
6
-
paragraph=This library includes important C++ functions, including cout and cin, printf and scanf. It also includes STL containers like vector and algorithms.
6
+
paragraph=This library includes important C++ functions, including cout and cin, printf and scanf. It also includes STL containers like vector and algorithm.
0 commit comments