#include <Plaquette.h>
// Define pins for LEDs
const int numLeds = 4;
// Create arrays for AnalogOut, SineWave, and SquareWave
AnalogOut leds[numLeds] = {11, 10, 9, 6}; // Analog outputs for LEDs
SineWave sineOsc[numLeds]; // Array of sine wave oscillators, one per LED
SquareWave squareOsc[numLeds]; // Array of square wave oscillators, one per LED
float controlDel[numLeds]; // Control variables for LEDs
// Phases for oscillators
const float sinePhases[] = {0.0, 0.25, 0.50, 0.75}; // Phase offsets for sine oscillators
const float squarePhases[] = {0.0, 0.25, 0.50, 0.75}; // Phase offsets for square oscillators
Chronometer cycleChrono; // Timer to control switching between sine and square waves
void begin() {
// Initialize all oscillators.
for (int i = 0; i < numLeds; i++) {
sineOsc[i].period(1.0); // Set period of each sine oscillator to 1.0
sineOsc[i].phase(sinePhases[i]); // Set phase offset for each sine oscillator
squareOsc[i].period(0.5); // Set period of each square oscillator to 0.5
squareOsc[i].phase(squarePhases[i]); // Set phase offset for each square oscillator
}
cycleChrono.start(); // Start the timer
}
void step() {
// Determine controlDel based on timing.
if (cycleChrono <= 10.0) {
// Use sine wave oscillators for the first 10 seconds
for (int i = 0; i < numLeds; i++) {
controlDel[i] = sineOsc[i];
}
}
else if (cycleChrono > 10.0 && cycleChrono <= 15.0) {
// Switch to square wave oscillators between 10 and 15 seconds
for (int i = 0; i < numLeds; i++) {
controlDel[i] = squareOsc[i];
}
}
else {
cycleChrono.start(); // Reset the timer if no conditions are met
}
// Update LEDs.
for (int i = 0; i < numLeds; i++) {
controlDel[i] >> leds[i]; // Assign control value to each LED
}
}