Mirko Pavleski
Published © GPL3+

DIY Analog Style Stereo VU Meter on I2C OLED

How to make an extremely simple but visually effective VU meter at 0.9 inches OLED displays SSD 1306.

BeginnerFull instructions provided10,968
DIY Analog Style Stereo VU Meter on I2C OLED

Things used in this project

Hardware components

Graphic OLED, 128 x 64
Graphic OLED, 128 x 64
×2
Arduino Nano R3
Arduino Nano R3
×2
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×2
Capacitor 10 µF
Capacitor 10 µF
×2
Capacitor 100 nF
Capacitor 100 nF
×2
Resistor 100k ohm
Resistor 100k ohm
×2
1N4148 – General Purpose Fast Switching
1N4148 – General Purpose Fast Switching
×2

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free

Story

Read more

Schematics

Schematic diagram

Code

CODE arc scale, mono

C/C++
/*  OLEDMeter was written to utilize any 128x64 display. I have only seen marginal attempts to
 *  animate meters and I hope this one will set a standard. Please feel free to modify and share
 *  this code for any 128x64 LCD or OLED. OLEDMeter sketch was written for use with I2C SSD1306.
 *  This code must be modified to work with other display devices.
 *  
 *  Working portion of code was taken from Adafruit Example Sound Level Sketch for the
 *  Adafruit Microphone Amplifier
 *  https://learn.adafruit.com/adafruit-microphone-amplifier-breakout/measuring-sound-levels
 *  
 *  Remaining code was written by Greg Stievenart with no claim to or any images or information 
 *  provided in this code. Freely published May 26, 2016.
 *  
 *  Software to convert background mask to 128x64 at: http://www.ablab.in/image2glcd-software/
 *  
 *  IMPORTANT: Sound source must be grounded to the Arduino or other MCU's to work. Usually the
 *  base sleeve contact on TRS or TRRS connector is the ground.
 */

#include <Wire.h>                     // requried to run I2C SSD1306
#include <SPI.h>                      // requried to run I2C SSD1306
#include <Adafruit_GFX.h>             // https://github.com/adafruit/Adafruit-GFX-Library
#include <Adafruit_SSD1306.h>          // https://github.com/wonho-maker/Adafruit_SSD1306

#define OLED_RESET 4                  // reset required for SSD1306

Adafruit_SSD1306 display(OLED_RESET);  // reset required for SSD1306

int analogInput = A0;                 // analog input for outside audio source
int hMeter = 65;                      // horizontal center for needle animation
int vMeter = 85;                      // vertical center for needle animation (outside of dislay limits)
int rMeter = 80;                      // length of needle animation or arch of needle travel

const int sampleWindow = 50;          // sample window width in mS (50 mS = 20Hz)
unsigned int sample;

// VU meter background mask image:
static const unsigned char PROGMEM VUMeter[] = { 
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x03, 0x00, 0x60, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x09, 0x04, 0x80, 0x21, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x01, 0x98, 0x08, 0x06, 0x03, 0x80, 0x21, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0xA4, 0x10, 0x09, 0x00, 0x80, 0x21, 0x20, 0x07, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0xA4, 0x10, 0x06, 0x03, 0x00, 0x20, 0xC0, 0x00, 0x80, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x71, 0x80, 0xA4, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x0A, 0x40, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3C, 0x00, 0x00,
  0x00, 0x00, 0x3A, 0x40, 0x00, 0x00, 0x02, 0x01, 0x00, 0x40, 0x80, 0x07, 0x00, 0x20, 0x00, 0x00,
  0x00, 0x00, 0x42, 0x40, 0x00, 0x08, 0x02, 0x01, 0x08, 0x40, 0x80, 0x00, 0x00, 0x38, 0x00, 0x00,
  0x00, 0x00, 0x79, 0x80, 0x04, 0x08, 0x02, 0x01, 0x08, 0x81, 0x10, 0x00, 0x00, 0x04, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x04, 0x08, 0x02, 0x01, 0x08, 0x81, 0x11, 0x04, 0x00, 0x38, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x02, 0x04, 0x02, 0x01, 0x08, 0x81, 0x21, 0x04, 0x00, 0x00, 0x08, 0x00,
  0x00, 0x00, 0x00, 0x84, 0x02, 0x04, 0x0F, 0xFF, 0xFF, 0xC3, 0xE2, 0x04, 0x00, 0x00, 0x08, 0x00,
  0x00, 0x00, 0x00, 0xC2, 0x01, 0x07, 0xF0, 0x00, 0x00, 0x3B, 0xFE, 0x08, 0x40, 0x40, 0x08, 0x00,
  0x00, 0xFE, 0x00, 0x62, 0x01, 0xF8, 0x00, 0x00, 0x00, 0x03, 0xFF, 0xE8, 0x40, 0x80, 0x7F, 0x00,
  0x00, 0x00, 0x00, 0x21, 0x1E, 0x00, 0x04, 0x00, 0x80, 0x00, 0x7F, 0xFE, 0x80, 0x80, 0x08, 0x00,
  0x00, 0x00, 0x03, 0x31, 0xE0, 0x00, 0x04, 0x00, 0x80, 0x04, 0x01, 0xFF, 0xC1, 0x00, 0x08, 0x00,
  0x00, 0x00, 0x07, 0x1E, 0x00, 0x40, 0x00, 0x00, 0x00, 0x04, 0x00, 0x1F, 0xFA, 0x00, 0x08, 0x00,
  0x00, 0x00, 0x07, 0xF0, 0x00, 0x40, 0x3B, 0x07, 0x60, 0x00, 0x00, 0x01, 0xFF, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x03, 0x80, 0x00, 0x00, 0x34, 0x81, 0x90, 0xCC, 0xC0, 0x00, 0x3F, 0xC0, 0x00, 0x00,
  0x00, 0x00, 0x0C, 0x00, 0x03, 0x30, 0x0C, 0x82, 0x90, 0x53, 0x20, 0x00, 0x07, 0xF8, 0x00, 0x00,
  0x00, 0x00, 0x70, 0x40, 0x00, 0xC8, 0x3B, 0x02, 0x60, 0x53, 0x20, 0x00, 0x00, 0xFE, 0x00, 0x00,
  0x00, 0x01, 0x80, 0x20, 0x01, 0xC8, 0x00, 0x00, 0x00, 0x4C, 0xC0, 0x00, 0x00, 0x3F, 0x80, 0x00,
  0x00, 0x06, 0x00, 0x00, 0x03, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xE0, 0x00,
  0x00, 0x08, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFC, 0x00,
  0x00, 0x30, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00,
  0x00, 0x00, 0x40, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
  0x00, 0x00, 0xA0, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x02, 0x02, 0x30, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x03, 0x06, 0x30, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01, 0x8C, 0x30, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0xD8, 0x30, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x70, 0x19, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x20, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

void setup(){

  pinMode(analogInput, INPUT);                             // analog input for outside audio source
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);                // needed for SSD1306 display
  display.clearDisplay();                                  // clears display from any library info displayed
  
  
}

void loop(){

/***********************************************************************
 Start of code taken from Adafruit Example Sound Level Sketch for the 
 Adafruit Microphone Amplifier
************************************************************************/
  
  unsigned long startMillis = millis();                    // start of sample window
  unsigned int PeaktoPeak = 0;                             // peak-to-peak level
  unsigned int SignalMax = 0;
  unsigned int SignalMin = 1024;

  while ( millis() - startMillis < sampleWindow ){

    sample = analogRead(analogInput);
    if (sample < 1024) {

      if (sample > SignalMax){

        SignalMax = sample;                                // saves just the max levels
      }

      else if (sample < SignalMin){

        SignalMin = sample;                                // saves just the min levels
      }
    }
  }

  PeaktoPeak = SignalMax - SignalMin;                      // max - min = peak-peak amplitude
  float MeterValue = PeaktoPeak * 330 / 1024;              // convert volts to arrow information

/****************************************************
 End of code taken from Adafruit Sound Level Sketch
*****************************************************/
  
  MeterValue = MeterValue - 34;                            // shifts needle to zero position
  display.clearDisplay();                                  // refresh display for next step
  display.drawBitmap(0, 0, VUMeter, 128, 64, WHITE);       // draws background
  int a1 = (hMeter + (sin(MeterValue / 57.296) * rMeter)); // meter needle horizontal coordinate
  int a2 = (vMeter - (cos(MeterValue / 57.296) * rMeter)); // meter needle vertical coordinate
  display.drawLine(a1, a2, hMeter, vMeter, WHITE);         // draws needle
  display.display();
}

CODE linear scale ,stereo

C/C++
/*  OLEDMeter was written to utilize any 128x64 display. I have only seen marginal attempts to
 *  animate meters and I hope this one will set a standard. Please feel free to modify and share
 *  this code for any 128x64 LCD or OLED. OLEDMeter sketch was written for use with I2C SSD1306.
 *  This code must be modified to work with other display devices.
 *  
 *  Working portion of code was taken from Adafruit Example Sound Level Sketch for the
 *  Adafruit Microphone Amplifier
 *  https://learn.adafruit.com/adafruit-microphone-amplifier-breakout/measuring-sound-levels
 *  
 *  Remaining code was written by Greg Stievenart with no claim to or any images or information 
 *  provided in this code. Freely published May 26, 2016.
 *  
 *  Software to convert background mask to 128x64 at: http://www.ablab.in/image2glcd-software/
 *  
 *  IMPORTANT: Sound source must be grounded to the Arduino or other MCU's to work. Usually the
 *  base sleeve contact on TRS or TRRS connector is the ground.
 */

#include <Wire.h>                     // requried to run I2C SSD1306
//#include <SPI.h>                      // requried to run I2C SSD1306
#include <Adafruit_GFX.h>             // https://github.com/adafruit/Adafruit-GFX-Library
#include <Adafruit_SSD1306.h>         // https://github.com/adafruit/Adafruit_SSD1306

#define OLED_RESET 4                  // reset required for SSD1306

Adafruit_SSD1306 display1(OLED_RESET);  // reset required for SSD1306
Adafruit_SSD1306 display2(OLED_RESET);  // reset required for SSD1306


int left = A0;                 // analog input for outside audio source
int right = A1;                 // analog input for outside audio source

int hMeter = 65;                      // horizontal center for needle animation
int vMeter = 85;                      // vertical center for needle animation (outside of dislay limits)
int rMeter = 80;                      // length of needle animation or arch of needle travel
float MeterValueLeft;
float MeterValueRight;
const int sampleWindow = 5;          // sample window width in mS (50 mS = 20Hz)
unsigned int sampleLeft;
unsigned int sampleRight;
unsigned int PeakRight = 400;                             // start needle fall max to min on start
unsigned int PeakLeft = 400;                             // start needle fall max to min on start
unsigned int fallTimeRight;          // needle fallspeed
unsigned int fallTimeLeft;          // needle fallspeed

// VU meter background mask image:
static const unsigned char PROGMEM VUMeter[] = { 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x1D, 0xC0, 0x00, 0x2E, 0x00, 0x00, 0x0E, 0x00, 0x00, 0xE0, 0x40, 0x1C, 0x00, 0x1C, 0x10, 
0x00, 0x05, 0x40, 0x00, 0x2A, 0x00, 0x00, 0x02, 0x00, 0x00, 0xA0, 0x40, 0x04, 0x00, 0x04, 0x10, 
0x1F, 0x1D, 0x40, 0x00, 0x2A, 0x00, 0x00, 0x0E, 0x00, 0x00, 0xA0, 0x40, 0x1C, 0x00, 0x1C, 0x7C, 
0x00, 0x11, 0x40, 0x00, 0x2A, 0x00, 0x00, 0x02, 0x00, 0x00, 0xA0, 0x40, 0x10, 0x00, 0x04, 0x10, 
0x00, 0x1D, 0xC0, 0x00, 0x2E, 0x00, 0x00, 0x0E, 0x00, 0x00, 0xE0, 0x40, 0x1C, 0x00, 0x1C, 0x10, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x02, 0x00, 0x00, 0x08, 0x00, 0x00, 0x04, 0x00, 0x00, 0x40, 0x40, 0x08, 0x00, 0x08, 0x00, 

0x00, 0x02, 0x00, 0x00, 0x08, 0x00, 0x00, 0x04, 0x00, 0x00, 0x40, 0x40, 0x08, 0x00, 0x08, 0x00, 
0x00, 0x02, 0x00, 0x00, 0x08, 0x08, 0x08, 0x04, 0x10, 0x40, 0x5F, 0xFF, 0xFF, 0xFF, 0xF8, 0x00, 
0x00, 0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xDF, 0xFF, 0xFF, 0xFF, 0xF8, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x01, 0x00, 0x00, 0x20, 0x00, 0x40, 0x01, 0x00, 0x10, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x03, 0x80, 0x01, 0xDC, 0x02, 0x38, 0x0E, 0xE0, 0xEE, 0x05, 0xDC, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x02, 0x80, 0x00, 0x54, 0x02, 0xA8, 0x08, 0xA0, 0xAA, 0x05, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x02, 0x80, 0x01, 0xD4, 0x02, 0xA8, 0x0E, 0xA0, 0xEA, 0x05, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x02, 0x80, 0x01, 0x14, 0x03, 0xA8, 0x0A, 0xA0, 0xAA, 0x05, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x03, 0x80, 0x01, 0xDC, 0x00, 0xB8, 0x0E, 0xE0, 0xEE, 0x05, 0xDC, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 

0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x08, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA2, 0x94, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA2, 0x94, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA2, 0x94, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA2, 0x94, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA2, 0x94, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA2, 0x94, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA2, 0x94, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 

0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA2, 0x94, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA2, 0x94, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0x14, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2A, 0x17, 0xD0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x08, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x07, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 
};

void setup(){
  Serial.begin(9600);

  pinMode(left, INPUT);                             // analog input for outside audio source
    pinMode(right, INPUT);                             // analog input for outside audio source

  display1.begin(SSD1306_SWITCHCAPVCC, 0x3C);                // needed for SSD1306 display1    3C
  display1.clearDisplay();  // clears display from any library info displayed
  
  display2.begin(SSD1306_SWITCHCAPVCC, 0x3D);                // needed for SSD1306 display     3D
  display2.clearDisplay();                                  // clears display from any library info displayed
 
}

void loop(){

  unsigned long startMillis = millis();                    // start of sample window
  unsigned int PeaktoPeakLeft = 0;                             // peak-to-peak level
  unsigned int SignalMaxLeft = 0;
  unsigned int SignalMinLeft = 1024;
  unsigned int PeaktoPeakRight = 0;                             // peak-to-peak level
  unsigned int SignalMaxRight = 0;
  unsigned int SignalMinRight = 1024;
  while ( millis() - startMillis < sampleWindow ){

    sampleLeft = analogRead(left);
    sampleRight = analogRead(right);

    if (sampleLeft < 1024) {

      if (sampleLeft > SignalMaxLeft){

        SignalMaxLeft = sampleLeft;                                // saves just the max levels
      }

      else if (sampleLeft < SignalMinLeft){

        SignalMinLeft = sampleLeft;                                // saves just the min levels
      }
    }
    if (sampleRight < 1024) {

      if (sampleRight > SignalMaxRight){

        SignalMaxRight = sampleRight;                                // saves just the max levels
      }

      else if (sampleRight < SignalMinRight){

        SignalMinRight = sampleRight;                                // saves just the min levels
      }
    }
   
  }

  PeaktoPeakLeft = SignalMaxLeft - SignalMinLeft;                      // max - min = peak-peak amplitude
  PeaktoPeakRight = SignalMaxRight - SignalMinRight;                   // max - min = peak-peak amplitude

   if (PeaktoPeakLeft > PeakLeft){

        PeakLeft = PeaktoPeakLeft;// saves just the min levels
      }else if(PeaktoPeakLeft < PeakLeft){
        fallTimeLeft = ((PeakLeft - PeaktoPeakLeft) / 2);
        PeakLeft = PeakLeft-fallTimeLeft;
      }
   if (PeaktoPeakRight > PeakRight){

        PeakRight = PeaktoPeakRight;// saves just the min levels
      }else if(PeaktoPeakRight < PeakRight){
        fallTimeRight = ((PeakRight - PeaktoPeakRight) / 2);
        PeakRight = PeakRight-fallTimeRight;
      }

    

  MeterValueLeft = PeakLeft ;              // convert volts to arrow information sensitivity 
  MeterValueRight = PeakRight ;              // convert volts to arrow information sensitivity 

 drawleft();
 drawright();
}

void drawleft(){
  




  MeterValueLeft = MeterValueLeft - 34;                            // shifts needle to zero position
  display1.clearDisplay();                                  // refresh display for next step
  display1.drawBitmap(0, 0, VUMeter, 128, 64, WHITE);       // draws background white
  int a1 = (hMeter + (sin(MeterValueLeft / 57.296) * rMeter)); // meter needle horizontal coordinate
  int a2 = (vMeter - (cos(MeterValueLeft / 57.296) * rMeter)); // meter needle vertical coordinate
  
display1.drawLine(a1-2, a2, hMeter-1, vMeter, BLACK);         // draws needle
display1.drawLine(a1-1, a2, hMeter-1, vMeter, WHITE);         // draws needle  
display1.drawLine(a1, a2, hMeter, vMeter, WHITE);         // draws needle
display1.drawLine(a1+1, a2, hMeter+1, vMeter, WHITE);         // draws needle  
display1.drawLine(a1+2, a2, hMeter+1, vMeter, BLACK);         // draws needle
  display1.display();
}
void drawright(){
  




  MeterValueRight = MeterValueRight - 44;                            // shifts needle to zero position
  display2.clearDisplay();                                  // refresh display for next step
  display2.drawBitmap(0, 0, VUMeter, 128, 64, WHITE);       // draws background white
  int a1 = (hMeter + (sin(MeterValueRight / 57.296) * rMeter)); // meter needle horizontal coordinate
  int a2 = (vMeter - (cos(MeterValueRight / 57.296) * rMeter)); // meter needle vertical coordinate
  display1.drawLine(a1-2, a2, hMeter-1, vMeter, BLACK);         // draws needle
display1.drawLine(a1-1, a2, hMeter-1, vMeter, WHITE);         // draws needle  
display1.drawLine(a1, a2, hMeter, vMeter, WHITE);         // draws needle
display1.drawLine(a1+1, a2, hMeter+1, vMeter, WHITE);         // draws needle  
display1.drawLine(a1+2, a2, hMeter+1, vMeter, BLACK);         // draws needle
  display2.display();
}

Credits

Mirko Pavleski

Mirko Pavleski

148 projects • 1275 followers

Comments