-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
52 changed files
with
2,405 additions
and
414 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
.. include:: defs.hrst | ||
|
||
[] (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 <https://www.arduino.cc/reference/en/language/variables/data-types/array/>`_. | ||
|
||
Arrays of Plaquette units such as :doc:`DigitalIn`. :doc:`SineOsc`, and :doc:`MinMaxScaler` can be easily created using the following syntax: | ||
|
||
.. code-block:: c++ | ||
|
||
UnitType array[] = { UnitType(...), UnitType(...), ... }; | ||
|
||
For example, the following code will create an array of three (3) digital outputs on pins 10, 11, and 12: | ||
|
||
.. code-block:: c++ | ||
|
||
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: | ||
|
||
.. code-block:: c++ | ||
|
||
DigitalOut leds[] = { 10, 11, 12 }; | ||
|
||
When more than a single parameter is used, however, it needs to be called explicitely with the unit name: | ||
|
||
.. code-block:: c++ | ||
|
||
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| | ||
--------- | ||
|
||
.. code-block:: c++ | ||
|
||
#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]; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,6 @@ Core structural functions and operators. | |
|
||
begin | ||
step | ||
array | ||
dot | ||
pipe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
examples/04.Generators/BlinkModulation/BlinkModulation.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Modulation | ||
* | ||
* Uses a low-frequency oscillator (LFO) to control the frequency of another | ||
* oscillator. | ||
* Sends values to the serial output: best visualized using the Arduino Serial Plotter. | ||
* | ||
* Created in 2019 by Sofian Audry | ||
* | ||
* This example code is in the public domain. | ||
*/ | ||
|
||
#include <Plaquette.h> | ||
|
||
// The main oscillator. | ||
SquareOsc osc; | ||
|
||
// The LFO. | ||
SineOsc lfo(20.0); // 20 seconds period | ||
|
||
// The LED. | ||
DigitalOut led(LED_BUILTIN); | ||
|
||
void begin() {} | ||
|
||
void step() { | ||
// Modulate oscillator BPM between 30 to 180. | ||
osc.bpm( lfo.mapTo(30, 180) ); | ||
|
||
// Send to LED. | ||
osc >> led; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* ArrayBlink | ||
* | ||
* Demonstrates the use of arrays to turn multiple LEDs on and off according | ||
* to different square oscillators. | ||
* | ||
* The circuit: | ||
* - Three LEDs. | ||
* - The anode of the LEDs are connected in series with a 220-ohm resistor to pins 4, 5, and 6. | ||
* - Their cathodes connect to ground. | ||
* | ||
* Created in 2024 by Sofian Audry | ||
* | ||
* This example code is in the public domain. | ||
*/ | ||
#include <Plaquette.h> | ||
|
||
// The LED. | ||
const int N_LEDS = 3; | ||
|
||
// A square-wave (on/off) oscillator for each LED. | ||
// - The first LED will blink once per second. | ||
// - The second LED will blink once every two seconds with a duty-cycle of 80%. | ||
// - The third LED will blink once every three seconds. | ||
SquareOsc oscillators[] = { | ||
SquareOsc(1.0), | ||
SquareOsc(2.0, 0.8), | ||
3.0 // shorthand for SquareOsc(3.0) | ||
}; | ||
|
||
// The three LEDs. | ||
DigitalOut leds[] = { 4, 5, 6 }; // shorthand for DigitalOut leds[] = { DigitalOut(4), DigitalOut(5), DigitalOut(6) }; | ||
|
||
void begin() {} | ||
|
||
void step() { | ||
// Send oscillator value to corresponding LED. | ||
for (int i=0; i<N_LEDS; i++) { | ||
oscillators[i] >> leds[i]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* ArrayBlink | ||
* | ||
* Demonstrates the use of arrays to create a VU-meter with 5 LEDs. | ||
* | ||
* The circuit: | ||
* - Five LEDs. | ||
* - The anode of the LEDs are connected in series with a 220-ohm resistor to pins 4 to 8. | ||
* - Their cathodes connect to ground. | ||
* | ||
* Created in 2024 by Sofian Audry | ||
* | ||
* This example code is in the public domain. | ||
*/ | ||
#include <Plaquette.h> | ||
|
||
// The LED. | ||
const int N_LEDS = 5; | ||
|
||
// An analog sensor such as a microphone or photocell. | ||
AnalogIn sensor(A0); | ||
|
||
// The three LEDs. | ||
DigitalOut leds[] = { 4, 5, 6, 7, 8 }; // shorthand for DigitalOut leds[] = { DigitalOut(4), DigitalOut(5), DigitalOut(6), ... }; | ||
|
||
void begin() {} | ||
|
||
void step() { | ||
// Map sensor value to number of LEDs to turn on. | ||
// NOTE: Due to the cast to int, the sensor value will need to be 1.0 (100%) to turn on all LEDs. | ||
// This can be adjusted to be more tolerant by changing the call to mapFrom01(sensor, 0, N_LEDS+1). | ||
int nLedsOn = (int)mapFrom01(sensor, 0, N_LEDS); | ||
|
||
// Light up LEDs. | ||
for (int i=0; i<N_LEDS; i++) { | ||
// Turn on LED if i < nLedsOn. | ||
(i < nLedsOn) >> leds[i]; | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.