StreamOut
An output unit that transmits values through a stream – for example, the Arduino serial line. Values are sent in clear text and separated by newlines and/or carriage returns.
Example
Outputs the number of seconds to serial.
#include <Plaquette.h>
StreamOut serialOut(Serial);
void begin() {}
void step() {
// Output the number of seconds
seconds() >> serialOut;
}
To run this example:
Upload the code.
In the Arduino software open the serial monitor: Tools > Serial Monitor.
Make sure the default baudrate of 9600 bps is selected.
You should see the seconds increase.
Close the monitor and open serial plotter: Tools > Serial Plotter.
You should see a graphical representation of the seconds.
Replace the line in
step()
by:sin(seconds()) >> serialOut
and upload. You should now see a sine wave signal in the serial plotter.
Reference
-
class StreamOut : public AnalogSource
Stream/serial output. Number of digits of precision is configurable.
Public Functions
-
StreamOut(Stream &stream = Serial)
Constructor.
- Parameters:
stream – a reference to a Stream object
-
virtual float put(float value)
Pushes value into the unit.
- Parameters:
value – the value sent to the unit
- Returns:
the new value of the unit
-
virtual void precision(uint8_t digits)
Sets precision of the output.
- Parameters:
digits – the number of digits to show after decimal point
-
inline virtual float get()
Returns value in [0, 1].
-
StreamOut(Stream &stream = Serial)