StreamIn

An input unit that can receive values transmitted through a stream – for example, the Arduino serial line. Values are sent in clear text and separated by newlines and/or carriage returns.

Example

Controls the value of a LED using serial. Try opening the serial monitor and sending values between 0 and 1.

#include <Plaquette.h>

StreamIn serialIn(Serial);

AnalogOut led(9);

void begin() {}

void step() {
  serialIn >> led;
}

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. Make sure one of the options “Newline”, “Carriage return”, or “Both NL + CR” is selected.

  5. Write a number between 0.0 and 1.0 and press “Enter”. This should allow you to set the LED intensity.

  6. Try different values.

Reference

class StreamIn : public AnalogSource

Stream/serial input. Reads float values using Arduino built-in parseFloat().

Public Functions

StreamIn(Stream &stream = Serial)

Constructor.

Parameters:

stream – a reference to a Stream object

inline virtual float mapTo(float toLow, float toHigh)

Maps value to new range.

inline virtual bool updated()

Returns true iff value was changed.

inline virtual void onUpdate(EventCallback callback)

Registers event callback on finish event.

inline virtual float get()

Returns value in [0, 1].

See Also