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:

  1. Upload the code.

  2. In the Arduino software open the serial monitor: Tools > Serial Monitor.

  3. Make sure the default baudrate of 9600 bps is selected.

  4. You should see the seconds increase.

  5. Close the monitor and open serial plotter: Tools > Serial Plotter.

  6. You should see a graphical representation of the seconds.

  7. 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.

Public Static Functions

static inline bool analogToDigital(float f)

Converts analog (float) value to digital (bool) value.

static inline float digitalToAnalog(bool b)

Converts digital (bool) value to analog (float) value.

See Also