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(Engine &engine = Engine::primary())
Default constructor.
- Parameters
engine – the engine running this unit
-
StreamOut(Stream &stream, Engine &engine = Engine::primary())
Constructor.
- Parameters
stream – a reference to a Stream object
engine – the engine running this unit
-
inline virtual float mapTo(float toLow, float toHigh)
Maps value to new range.
-
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].
-
inline float seconds() const
Returns engine time in seconds.
-
inline uint32_t milliSeconds() const
Returns engine time in milliseconds.
-
inline uint64_t microSeconds() const
Returns engine time in microseconds.
-
inline unsigned long nSteps() const
Returns number of engine steps.
-
inline float sampleRate() const
Returns engine sample rate.
-
inline float samplePeriod() const
Returns enginesample period.
-
inline operator float()
Object can be used directly to access its value.
-
inline explicit operator bool()
Operator that allows usage in conditional expressions.
-
StreamOut(Engine &engine = Engine::primary())