sensors_clue-sensor-plotter-class-plotsource-trio-v4.png
UML class diagram for plotting sources. The abstract class is shown with three derived classes, two for sensors on the CLUE board and one for input pad(s).

PlotSource is an abstract class. This means that it is not intended for direct use but exists as a parent for sub-classes. It is also defining the interface for children with the start(), stop() and data() operations (a UML term encompassing methods).

Data Sources for Plotting

The CLUE board has many sensors and inputs which can be used as data sources for plotting. The data output from all of these sensors and analogue input(s) are ultimately represented by either one number or a list of numbers per sample read. This commonality suggests they can be represented by a single class providing the interface to the rest of the program. The per-sensor code can be implemented in a sub-class derived from a base class using inheritance. UML diagrams depict inheritance with an unfilled, triangular arrow head.

The sub-classes are listed below with their name together with with any processing performed, the number of values returned by data() and the units for values:

  1. AccelerometerPlotSource - none - 3 values - ms-2.
  2. ColorPlotSource - discard data from clear sensor leaving red, green and blue values - 3 values - integer.
  3. GyroPlotSource - none - 3 values - degrees per second (dps).
  4. HumidityPlotSource - none - 1 value - percentage.
  5. IlluminatedColorPlotSource - only pass a single value from sensor selected at instantiation - 1 value - integer.
  6. MagnetometerPlotSource - none - 3 values - uT.
  7. PinPlotSource - converted to voltage - 1 value per pin, maximum of 3 - V.
  8. PressurePlotSource - optionally converted to inches of mercury - 1 value - hPa or inHg.
  9. ProximityPlotSource - none - 1 value - integer.
  10. TemperaturePlotSource - optionally converted to Fahrenheit - 1 value - degrees Celsius or Fahrenheit.
  11. VolumePlotSource - conversion to decibel scale - 1 value - dB.

The colour sensor here is actually represented by two classes. There are different ways to design the illuminated vs the non-illuminated colour plot source.

  1. The variation in behaviour can be achieved with conditional logic inside a single class. The selection of the desired behaviour can be achieved in many ways:
    1. creation of two objects with the variety passed as a parameter as the object is constructed;
    2. a single object with additional methods extending the interface;
    3. a single object with an optional parameter to the existing data() method.
  2. Increased use of inheritance with two or three classes, e.g. IlluminatedColorPlotSource could be derived from ColorPlotSource and optionally a NonIlluminatedColorPlotSource could be created.
  3. Two classes derived from PlotSource.

The final option was the one chosen with the IlluminatedColorPlotSource using the start() and stop() methods to turn on the CLUE's pair of bright, white, forward-facing LEDs for the duration of the illuminated plotting. The sensor's gain is also set a little higher.

This guide was first published on Apr 01, 2020. It was last updated on Jan 28, 2020.

This page (PlotSource Class) was last updated on Mar 05, 2020.

Text editor powered by tinymce.