Plotter
An output unit that streams values to a text-based output using a configurable format. The Plotter is designed for quick signal inspection in tools such as the Arduino Serial Plotter, while also supporting structured formats (e.g., CSV, JSON) for logging and external processing.
Values are sent in clear text and arranged in rows. Each call to put() (usually
via the >> operator) appends one value to the current row; the row is then finalized
automatically at the end of the Plaquette engine step (or when the Plotter decides to
close the row).
The Plotter can optionally take a comma-separated list of labels (const char*)
such as "wave,signal". When labels are provided, some formats will include a header
(e.g., CSV) or will use key/value rendering (e.g., JSON objects, "label":value).
Example
Streaming multiple values per row, with labels.
Tip
On Arduino, you can visualize the data using the Serial Plotter by selecting Tools > Serial Plotter.
#include <Plaquette.h>
//declare the baud rate to suit your application.
//OPTIONAL: After declaring the baud rate,
//you can create labels for incoming signals with a single comma-separated string.
Plotter plotter(115200, "wave,signal");
Wave wave(SINE);
Signal signal;
void step() {
wave >> plotter;
signal >> plotter;
}
You can add labels to the output by specifying them at the creation of the Plotter unit:
Plotter plotter(115200, "wave,signal");
You can also output in Comma Separated Values format by using presets
(PLOTTER_CSV, PLOTTER_JSON):
void begin() {
plotter.format(PLOTTER_CSV);
}
Depending on the chosen format and whether labels are provided, labels may be rendered as a
header (CSV), as keys (JSON objects), or as label:value pairs (default space-delimited mode with
labels).
Reference
-
class Plotter : public pq::Unit
Public Functions
-
inline const char *labels() const
Returns labels.
-
void format(PlotterFormatPreset preset)
Sets format based on preset.
-
void format(PlotterFormat format)
Sets format based on custom format.
-
inline PlotterFormat format()
Returns current format.
-
inline void precision(uint8_t digits)
Sets decimal precision of values.
- Parameters
digits – the number of digits after the point
-
inline uint8_t precision() const
Returns the decimal precision of values.
-
virtual float put(float value) override
Pushes value into the unit.
- Parameters
value – the value sent to the unit
- Returns
the new value of the unit
-
inline virtual float get() override
Returns last value.
-
void beginPlot()
Begins new plot.
-
void endPlot()
Ends current plot.
-
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 virtual float mapTo(float toLow, float toHigh)
Maps value to new range.
This function guarantees that the value is within [toLow, toHigh]. If the unit’s values are unbounded, returns get() constrained to [toLow, toHigh].
-
inline explicit operator bool()
Operator that allows usage in conditional expressions.
Public Static Functions
-
static PlotterFormat formatFromPreset(PlotterFormatPreset preset, const char *labelsSchema = nullptr)
Returns a PlotterFormat based on presets and labels.
-
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.
-
inline const char *labels() const