[] (arrays)

An array is a collection of variables or objects that are accessed with an index number. Arrays can be complicated, but using simple arrays is relatively straightforward.

For a general description of arrays, please refer to this page.

Arrays of Plaquette units such as DigitalIn. SineOsc, and MinMaxScaler can be easily created using the following syntax:

UnitType array[] = { UnitType(...), UnitType(...), ... };

For example, the following code will create an array of three (3) digital outputs on pins 10, 11, and 12:

DigitalOut leds[] = { DigitalOut(10), DigitalOut(11), DigitalOut(12) };

When initializing a unit with a single parameter, one can simply use the value of the parameter at creation time. Hence the previous code could be rewritten as:

DigitalOut leds[] = { 10, 11, 12 };

When more than a single parameter is used, however, it needs to be called explicitely with the unit name:

SquareOsc oscillators[] = { 1.0, 2.0, SquareOsc(3.0, 0.8) };

Warning

Units in array need to be all of the same type. In other words, it is not currently possible to mix different types of objects such as DigitalIn and SquareOsc in the same array.

Example

#include <Plaquette.h>

AnalogOut leds[] = { 9, 10, 11 };

// Creates three triangle oscillators with a 2 seconds period, with different width.
TriOsc oscillators[] = { TriOsc(2.0, 0.0), 2.0, TriOsc(2.0, 1.0) };

void begin() {}

void step() {
  // Send each oscillator to its corresponding LED.
  for (int i=0; i<3; i++) {
    oscillators[i] >> leds[i];
  }
}