Control Surface 2.1.0
MIDI Control Surface library for Arduino
Loading...
Searching...
No Matches
2.VU-Meter-OLED-USB-DAC.ino

2.VU-Meter-OLED-USB-DAC

This example shows the usage of the AudioVU and AnalogVUDisplay classes of the Control Surface library.

It displays two analog-style VU meters on two 128×64 OLED displays.
The VU meters imitate the inertia and ballistics of real analog VU meters.

It acts as a USB Audio DAC (Digital-to-Analog Converter).

Boards: 🛈
Teensy 3.x

Connections

Add a capacitor between the reset pin of the displays and ground, and a resistor from reset to 3.3V. The values are not critical, 0.1µF and 10kΩ work fine.
You do need some way to reset the displays, without it, it won't work.
Alternatively, you could use an IO pin from the Teensy to reset the displays, but this just "wastes" a pin.

Behavior

Upload the sketch, and select the Control Surface as the audio output of your computer. Connect the output of the DAC to a pair of headphones or powered speakers, and play some music.
You should see the VU meters come to life and jump around to the music.

You can now adjust the volume using the potentiometer on pin A0, and the gain/sensitivity of the meters using the potentiometer on pin A1.

Mapping

None.

Demo

Written by PieterP, 2019-08-09
https://github.com/tttapa/Control-Surface

#include <Control_Surface.h> // Include the Control Surface library
// Include the display interface you'd like to use
// #define DIGITAL_VU
// ----------------------------- Display setup ------------------------------ //
// ========================================================================== //
constexpr uint8_t SCREEN_WIDTH = 128;
constexpr uint8_t SCREEN_HEIGHT = 64;
constexpr int8_t OLED_DC = 17; // Data/Command pin of the display
constexpr int8_t OLED_reset = -1; // Use the external RC circuit for reset
constexpr int8_t OLED_CS_L = 10; // Chip Select pin of the left display
constexpr int8_t OLED_CS_R = 18; // Chip Select pin of the right display
// Instantiate the displays
};
// Instantiate the displays
};
// --------------------------- Display interface ---------------------------- //
// ========================================================================== //
// Implement the display interface, specifically, the begin and drawBackground
// methods.
// If you want, you can draw a background image of a VU meter first, and then
// draw the needle on top.
public:
void begin() override {
// Initialize the Adafruit_SSD1306 display
if (!disp.begin())
FATAL_ERROR(F("SSD1306 allocation failed."), 0x1306);
#ifdef DIGITAL_VU
disp.setRotation(1); // Rotate the display in portrait mode
#endif
// If you override the begin method, remember to call the super class method
}
void drawBackground() override {}
// --------------------------- Audio connections ---------------------------- //
// ========================================================================== //
// Connect the input to the mixers (volume control), the input to the RMS
// meters, and the mixers to the output
// ----------------------------- Volume control ----------------------------- //
// ========================================================================== //
// ------------------------------- VU Meters -------------------------------- //
// ========================================================================== //
#ifdef DIGITAL_VU
#else
display_L, // Display to display on
vu_L, // VU meter to display
{63, 63}, // Location of the needle pivot
63, // Length of the needle
-140 * PI / 180, // Minimum angle (radians)
100 * PI / 180, // Total angle range (radians)
WHITE, // Color
};
// Note that the y axis points downwards (as is common in computer graphics).
// This means that a positive angle is clockwise, and -140° lies in the top left
// quadrant
display_R, vu_R, {63, 63}, 63, -140 * PI / 180, 100 * PI / 180, WHITE,
};
#endif
// ------------------------------- Gain knob -------------------------------- //
// ========================================================================== //
constexpr float maxGain = 5;
// --------------------------------- Setup ---------------------------------- //
// ========================================================================== //
void setup() {
display_L.begin();
display_R.begin();
}
// ---------------------------------- Loop ---------------------------------- //
// ========================================================================== //
void loop() {
const unsigned long frametime = 1'000'000 / MAX_FPS;
static unsigned long previousFrameTime = micros();
Updatable<AudioVU>::updateAll(); // Update VU meters
Control_Surface.updateDisplays(); // Update displays
Updatable<Potentiometer>::updateAll(); // Update volume controls
}
if (gainKnob.update()) {
float gain = gainKnob.getFloatValue() * maxGain;
vu_L.setGain(gain);
vu_R.setGain(gain);
}
}
The main header file that includes all Control-Surface header files.
Control_Surface_ & Control_Surface
A predefined instance of the Control Surface to use in the Arduino sketches.
constexpr uint8_t MAX_FPS
The maximum frame rate of the displays.
A class that reads and filters an analog input.
static void setupADC()
Select the configured ADC resolution.
A super class for object that have to be updated regularly.
A VU meter that reads from an Audio stream using the Analyzer class.
Definition AudioVU.hpp:16
void updateDisplays()
Clear, draw and display all displays that contain display elements that have changed.
virtual void begin()
Initialize the display.
Displays a MCU level meter.
Definition VUDisplay.hpp:16
static MovingCoilBallistics noOvershoot(float Tsfactor=1.0)
static MovingCoilBallistics responsiveVU(float Tsfactor=2.0)
This class creates a mapping between the Adafruit_SSD1306 display driver and the general display inte...
void drawBackground() override=0
Draw a custom background.
A class for controlling the volume of AudioMixer4 objects using a potentiometer.
Array< T, N > copyAs(const Array< U, N > &src)
Copy an Array to an Array of a different type.
#define FATAL_ERROR(msg, errc)
Print the error message and error code, and stop the execution.
Definition Error.hpp:57
static constexpr Frequency SPI_MAX_SPEED
constexpr Note F
F (Fa)
Definition Notes.hpp:61