Monitor

An output unit that writes textual information to a print device, typically the serial line. The Monitor is intended for logging, debugging, and human-readable output, rather than structured data plotting like the Plotter.

To create a monitor on the default serial port with a specific baudrate:

Monitor monitor(baudrate);

Plaquette automatically uses the first Monitor you create as the default device where information is printed. This means that instead of writing:

monitor.println("Hello world!");

You can just write:

println("Hello world!");

Tip

On Arduino, you can read the text printed by the Monitor unit using the Serial Monitor by selecting Tools > Serial Monitor. Make sure the baudrate matches the value used to create the Monitor.

Example

Printing messages and values to the serial monitor.

#include <Plaquette.h>

Monitor monitor(115200);

void step() {
  println("Stepping...");

  print("Seconds: ");
  seconds >> monitor;
  println(); // new line
}

Notes and Warnings

  • The Monitor is not intended for structured data export or plotting; use Plotter for that purpose.

  • Blocking read operations (such as readStringUntil()) are intentionally not exposed to avoid unintended blocking behavior.

  • Precision for numeric output can be configured on the Monitor by calling its function precision() and applies to floating-point values printed through it.

Reference

class Monitor : public pq::Unit, public Print

Write-only monitor unit for textual output.

Monitor is a Plaquette Unit and a Print proxy. It is intended for human-readable output (debugging, status messages) and deliberately does not expose Stream read functionality to avoid blocking behavior.

The backend can be any Print-compatible object (Serial, file, etc.). When bound to a serial device, Monitor can auto-start it at a given baud rate.

Public Functions

explicit Monitor(unsigned long baudRate, Engine &engine = Engine::primary())

Construct a Monitor using the default Serial device.

Monitor(SerialType &device, unsigned long baudRate, Engine &engine = Engine::primary())

Construct a Monitor using a specific serial device.

explicit Monitor(Print &device, Engine &engine = Engine::primary())

Construct a Monitor using a generic Print backend.

No auto-start is performed.

inline Print &device() const

Get the current Print backend.

void precision(uint8_t digits)

Set the number of digits to print after the decimal point.

inline uint8_t precision() const

Get the number of digits to print after the decimal point by default.

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 value (last value that was put()).

virtual size_t write(uint8_t b) override

Core Print override.

All print()/println() calls funnel through this method.

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