25浏览
查看: 25|回复: 3

[项目] 【Arduino 动手做】I2C OLED 上的 DIY 模拟式立体声 VU 表

[复制链接]
如何制作一个非常简单但视觉上有效的 0.9 英寸 OLED 显示器 VU 表 SSD 1306。

这次,我将向您展示如何在小型 0.96 英寸 OLED 显示器上制作模拟式立体 VU 表。前段时间我收到了非常适合此目的的小型黄色 OLED 显示器。

该设备是根据 Arduino.cc 论坛中的“stevenart”的说明制作的,您还可以在论坛中找到原始代码(适用于 SH1106 Oled)。具体来说,在这种情况下,代码略有修改(SSD1306 Oled),并且在硬件中,部分添加了一个简单的输入电路(包络跟随器),以便 VU 表可以直接连接到音频放大器的输出。该设备的构建非常简单,并且只包含几个组件。

可以看出,VU 表的每个通道分别包含两个相同的组件。它可以只用一个 Arduino 制成,但在这种情况下,OLED 显示器必须具有不同的 I2C 地址。我的 OLED 显示器具有相同的 I2C 地址,因此我不得不制作两个相同的设备,它们的成本只比 Arduino 高几美元。但是,如果您能够获得具有不同地址的 Oled 显示器,或者有可能根据网上给出的一些说明通过焊接更改一个显示器的地址,那就更好了。以下是具有线性刻度和弧刻度的 VU 仪表的代码。对于 Reverse light (倒车灯) 修改,需要执行以下作:
在 viod 设置之后:
display.clearDisplay();

我们需要添加:

display.invertDisplay(true);

所以一个通道的组成部分是:
- Arduino 微控制器
- SSD1306 个 0.96 英寸小型 Oled 显示屏
- 两个电阻器
- 一个电容器
- 和电位器
另一个通道是相同的。让我提一下,在现场观看时,箭头的移动是流畅的。最后,将设备安装在由 PVC 材料制成的合适盒子中,并衬有自粘彩色墙纸。

【Arduino 动手做】I2C OLED 上的 DIY 模拟式立体声 VU 表图3

【Arduino 动手做】I2C OLED 上的 DIY 模拟式立体声 VU 表图1

【Arduino 动手做】I2C OLED 上的 DIY 模拟式立体声 VU 表图5

【Arduino 动手做】I2C OLED 上的 DIY 模拟式立体声 VU 表图4

【Arduino 动手做】I2C OLED 上的 DIY 模拟式立体声 VU 表图2

驴友花雕  中级技神
 楼主|

发表于 5 小时前

【Arduino 动手做】I2C OLED 上的 DIY 模拟式立体声 VU 表

本帖最后由 驴友花雕 于 2025-6-23 07:40 编辑

项目代码:
CODE 弧标尺,单屏:

  1. /*  OLEDMeter was written to utilize any 128x64 display. I have only seen marginal attempts to
  2. *  animate meters and I hope this one will set a standard. Please feel free to modify and share
  3. *  this code for any 128x64 LCD or OLED. OLEDMeter sketch was written for use with I2C SSD1306.
  4. *  This code must be modified to work with other display devices.
  5. *  
  6. *  Working portion of code was taken from Adafruit Example Sound Level Sketch for the
  7. *  Adafruit Microphone Amplifier
  8. *  https://learn.adafruit.com/adafruit-microphone-amplifier-breakout/measuring-sound-levels
  9. *  
  10. *  Remaining code was written by Greg Stievenart with no claim to or any images or information
  11. *  provided in this code. Freely published May 26, 2016.
  12. *  
  13. *  Software to convert background mask to 128x64 at: http://www.ablab.in/image2glcd-software/
  14. *  
  15. *  IMPORTANT: Sound source must be grounded to the Arduino or other MCU's to work. Usually the
  16. *  base sleeve contact on TRS or TRRS connector is the ground.
  17. */
  18. #include <Wire.h>                     // requried to run I2C SSD1306
  19. #include <SPI.h>                      // requried to run I2C SSD1306
  20. #include <Adafruit_GFX.h>             // https://github.com/adafruit/Adafruit-GFX-Library
  21. #include <Adafruit_SSD1306.h>          // https://github.com/wonho-maker/Adafruit_SSD1306
  22. #define OLED_RESET 4                  // reset required for SSD1306
  23. Adafruit_SSD1306 display(OLED_RESET);  // reset required for SSD1306
  24. int analogInput = A0;                 // analog input for outside audio source
  25. int hMeter = 65;                      // horizontal center for needle animation
  26. int vMeter = 85;                      // vertical center for needle animation (outside of dislay limits)
  27. int rMeter = 80;                      // length of needle animation or arch of needle travel
  28. const int sampleWindow = 50;          // sample window width in mS (50 mS = 20Hz)
  29. unsigned int sample;
  30. // VU meter background mask image:
  31. static const unsigned char PROGMEM VUMeter[] = {
  32.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  33.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  34.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  35.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  36.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  37.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x03, 0x00, 0x60, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
  38.   0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x09, 0x04, 0x80, 0x21, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
  39.   0x00, 0x00, 0x00, 0x01, 0x98, 0x08, 0x06, 0x03, 0x80, 0x21, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
  40.   0x00, 0x00, 0x00, 0x00, 0xA4, 0x10, 0x09, 0x00, 0x80, 0x21, 0x20, 0x07, 0x00, 0x00, 0x00, 0x00,
  41.   0x00, 0x00, 0x00, 0x00, 0xA4, 0x10, 0x06, 0x03, 0x00, 0x20, 0xC0, 0x00, 0x80, 0x00, 0x00, 0x00,
  42.   0x00, 0x00, 0x71, 0x80, 0xA4, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
  43.   0x00, 0x00, 0x0A, 0x40, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3C, 0x00, 0x00,
  44.   0x00, 0x00, 0x3A, 0x40, 0x00, 0x00, 0x02, 0x01, 0x00, 0x40, 0x80, 0x07, 0x00, 0x20, 0x00, 0x00,
  45.   0x00, 0x00, 0x42, 0x40, 0x00, 0x08, 0x02, 0x01, 0x08, 0x40, 0x80, 0x00, 0x00, 0x38, 0x00, 0x00,
  46.   0x00, 0x00, 0x79, 0x80, 0x04, 0x08, 0x02, 0x01, 0x08, 0x81, 0x10, 0x00, 0x00, 0x04, 0x00, 0x00,
  47.   0x00, 0x00, 0x00, 0x00, 0x04, 0x08, 0x02, 0x01, 0x08, 0x81, 0x11, 0x04, 0x00, 0x38, 0x00, 0x00,
  48.   0x00, 0x00, 0x00, 0x00, 0x02, 0x04, 0x02, 0x01, 0x08, 0x81, 0x21, 0x04, 0x00, 0x00, 0x08, 0x00,
  49.   0x00, 0x00, 0x00, 0x84, 0x02, 0x04, 0x0F, 0xFF, 0xFF, 0xC3, 0xE2, 0x04, 0x00, 0x00, 0x08, 0x00,
  50.   0x00, 0x00, 0x00, 0xC2, 0x01, 0x07, 0xF0, 0x00, 0x00, 0x3B, 0xFE, 0x08, 0x40, 0x40, 0x08, 0x00,
  51.   0x00, 0xFE, 0x00, 0x62, 0x01, 0xF8, 0x00, 0x00, 0x00, 0x03, 0xFF, 0xE8, 0x40, 0x80, 0x7F, 0x00,
  52.   0x00, 0x00, 0x00, 0x21, 0x1E, 0x00, 0x04, 0x00, 0x80, 0x00, 0x7F, 0xFE, 0x80, 0x80, 0x08, 0x00,
  53.   0x00, 0x00, 0x03, 0x31, 0xE0, 0x00, 0x04, 0x00, 0x80, 0x04, 0x01, 0xFF, 0xC1, 0x00, 0x08, 0x00,
  54.   0x00, 0x00, 0x07, 0x1E, 0x00, 0x40, 0x00, 0x00, 0x00, 0x04, 0x00, 0x1F, 0xFA, 0x00, 0x08, 0x00,
  55.   0x00, 0x00, 0x07, 0xF0, 0x00, 0x40, 0x3B, 0x07, 0x60, 0x00, 0x00, 0x01, 0xFF, 0x00, 0x00, 0x00,
  56.   0x00, 0x00, 0x03, 0x80, 0x00, 0x00, 0x34, 0x81, 0x90, 0xCC, 0xC0, 0x00, 0x3F, 0xC0, 0x00, 0x00,
  57.   0x00, 0x00, 0x0C, 0x00, 0x03, 0x30, 0x0C, 0x82, 0x90, 0x53, 0x20, 0x00, 0x07, 0xF8, 0x00, 0x00,
  58.   0x00, 0x00, 0x70, 0x40, 0x00, 0xC8, 0x3B, 0x02, 0x60, 0x53, 0x20, 0x00, 0x00, 0xFE, 0x00, 0x00,
  59.   0x00, 0x01, 0x80, 0x20, 0x01, 0xC8, 0x00, 0x00, 0x00, 0x4C, 0xC0, 0x00, 0x00, 0x3F, 0x80, 0x00,
  60.   0x00, 0x06, 0x00, 0x00, 0x03, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xE0, 0x00,
  61.   0x00, 0x08, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFC, 0x00,
  62.   0x00, 0x30, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00,
  63.   0x00, 0x00, 0x40, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
  64.   0x00, 0x00, 0xA0, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  65.   0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x02, 0x02, 0x30, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  66.   0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x03, 0x06, 0x30, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  67.   0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01, 0x8C, 0x30, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  68.   0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0xD8, 0x30, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  69.   0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x70, 0x19, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  70.   0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x20, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  71.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  72.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  73.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  74.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  75.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  76.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  77.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  78.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  79.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  80.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  81.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  82.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  83.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  84.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  85.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  86.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  87.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  88.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  89.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  90.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  91.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  92.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  93.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  94.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  95.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  96. };
  97. void setup(){
  98.   pinMode(analogInput, INPUT);                             // analog input for outside audio source
  99.   display.begin(SSD1306_SWITCHCAPVCC, 0x3C);                // needed for SSD1306 display
  100.   display.clearDisplay();                                  // clears display from any library info displayed
  101.   
  102.   
  103. }
  104. void loop(){
  105. /***********************************************************************
  106. Start of code taken from Adafruit Example Sound Level Sketch for the
  107. Adafruit Microphone Amplifier
  108. ************************************************************************/
  109.   
  110.   unsigned long startMillis = millis();                    // start of sample window
  111.   unsigned int PeaktoPeak = 0;                             // peak-to-peak level
  112.   unsigned int SignalMax = 0;
  113.   unsigned int SignalMin = 1024;
  114.   while ( millis() - startMillis < sampleWindow ){
  115.     sample = analogRead(analogInput);
  116.     if (sample < 1024) {
  117.       if (sample > SignalMax){
  118.         SignalMax = sample;                                // saves just the max levels
  119.       }
  120.       else if (sample < SignalMin){
  121.         SignalMin = sample;                                // saves just the min levels
  122.       }
  123.     }
  124.   }
  125.   PeaktoPeak = SignalMax - SignalMin;                      // max - min = peak-peak amplitude
  126.   float MeterValue = PeaktoPeak * 330 / 1024;              // convert volts to arrow information
  127. /****************************************************
  128. End of code taken from Adafruit Sound Level Sketch
  129. *****************************************************/
  130.   
  131.   MeterValue = MeterValue - 34;                            // shifts needle to zero position
  132.   display.clearDisplay();                                  // refresh display for next step
  133.   display.drawBitmap(0, 0, VUMeter, 128, 64, WHITE);       // draws background
  134.   int a1 = (hMeter + (sin(MeterValue / 57.296) * rMeter)); // meter needle horizontal coordinate
  135.   int a2 = (vMeter - (cos(MeterValue / 57.296) * rMeter)); // meter needle vertical coordinate
  136.   display.drawLine(a1, a2, hMeter, vMeter, WHITE);         // draws needle
  137.   display.display();
  138. }
复制代码


回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 5 小时前

【Arduino 动手做】I2C OLED 上的 DIY 模拟式立体声 VU 表

CODE 线性刻度,立体声双屏:
  1. /*  OLEDMeter was written to utilize any 128x64 display. I have only seen marginal attempts to
  2. *  animate meters and I hope this one will set a standard. Please feel free to modify and share
  3. *  this code for any 128x64 LCD or OLED. OLEDMeter sketch was written for use with I2C SSD1306.
  4. *  This code must be modified to work with other display devices.
  5. *  
  6. *  Working portion of code was taken from Adafruit Example Sound Level Sketch for the
  7. *  Adafruit Microphone Amplifier
  8. *  https://learn.adafruit.com/adafruit-microphone-amplifier-breakout/measuring-sound-levels
  9. *  
  10. *  Remaining code was written by Greg Stievenart with no claim to or any images or information
  11. *  provided in this code. Freely published May 26, 2016.
  12. *  
  13. *  Software to convert background mask to 128x64 at: http://www.ablab.in/image2glcd-software/
  14. *  
  15. *  IMPORTANT: Sound source must be grounded to the Arduino or other MCU's to work. Usually the
  16. *  base sleeve contact on TRS or TRRS connector is the ground.
  17. */
  18. #include <Wire.h>                     // requried to run I2C SSD1306
  19. //#include <SPI.h>                      // requried to run I2C SSD1306
  20. #include <Adafruit_GFX.h>             // https://github.com/adafruit/Adafruit-GFX-Library
  21. #include <Adafruit_SSD1306.h>         // https://github.com/adafruit/Adafruit_SSD1306
  22. #define OLED_RESET 4                  // reset required for SSD1306
  23. Adafruit_SSD1306 display1(OLED_RESET);  // reset required for SSD1306
  24. Adafruit_SSD1306 display2(OLED_RESET);  // reset required for SSD1306
  25. int left = A0;                 // analog input for outside audio source
  26. int right = A1;                 // analog input for outside audio source
  27. int hMeter = 65;                      // horizontal center for needle animation
  28. int vMeter = 85;                      // vertical center for needle animation (outside of dislay limits)
  29. int rMeter = 80;                      // length of needle animation or arch of needle travel
  30. float MeterValueLeft;
  31. float MeterValueRight;
  32. const int sampleWindow = 5;          // sample window width in mS (50 mS = 20Hz)
  33. unsigned int sampleLeft;
  34. unsigned int sampleRight;
  35. unsigned int PeakRight = 400;                             // start needle fall max to min on start
  36. unsigned int PeakLeft = 400;                             // start needle fall max to min on start
  37. unsigned int fallTimeRight;          // needle fallspeed
  38. unsigned int fallTimeLeft;          // needle fallspeed
  39. // VU meter background mask image:
  40. static const unsigned char PROGMEM VUMeter[] = {
  41. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  42. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  43. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  44. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  45. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  46. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  47. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  48. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  49. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  50. 0x00, 0x1D, 0xC0, 0x00, 0x2E, 0x00, 0x00, 0x0E, 0x00, 0x00, 0xE0, 0x40, 0x1C, 0x00, 0x1C, 0x10,
  51. 0x00, 0x05, 0x40, 0x00, 0x2A, 0x00, 0x00, 0x02, 0x00, 0x00, 0xA0, 0x40, 0x04, 0x00, 0x04, 0x10,
  52. 0x1F, 0x1D, 0x40, 0x00, 0x2A, 0x00, 0x00, 0x0E, 0x00, 0x00, 0xA0, 0x40, 0x1C, 0x00, 0x1C, 0x7C,
  53. 0x00, 0x11, 0x40, 0x00, 0x2A, 0x00, 0x00, 0x02, 0x00, 0x00, 0xA0, 0x40, 0x10, 0x00, 0x04, 0x10,
  54. 0x00, 0x1D, 0xC0, 0x00, 0x2E, 0x00, 0x00, 0x0E, 0x00, 0x00, 0xE0, 0x40, 0x1C, 0x00, 0x1C, 0x10,
  55. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  56. 0x00, 0x02, 0x00, 0x00, 0x08, 0x00, 0x00, 0x04, 0x00, 0x00, 0x40, 0x40, 0x08, 0x00, 0x08, 0x00,
  57. 0x00, 0x02, 0x00, 0x00, 0x08, 0x00, 0x00, 0x04, 0x00, 0x00, 0x40, 0x40, 0x08, 0x00, 0x08, 0x00,
  58. 0x00, 0x02, 0x00, 0x00, 0x08, 0x08, 0x08, 0x04, 0x10, 0x40, 0x5F, 0xFF, 0xFF, 0xFF, 0xF8, 0x00,
  59. 0x00, 0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xDF, 0xFF, 0xFF, 0xFF, 0xF8, 0x00,
  60. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  61. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  62. 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
  63. 0x01, 0x00, 0x00, 0x20, 0x00, 0x40, 0x01, 0x00, 0x10, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
  64. 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
  65. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  66. 0x03, 0x80, 0x01, 0xDC, 0x02, 0x38, 0x0E, 0xE0, 0xEE, 0x05, 0xDC, 0x00, 0x00, 0x00, 0x00, 0x00,
  67. 0x02, 0x80, 0x00, 0x54, 0x02, 0xA8, 0x08, 0xA0, 0xAA, 0x05, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00,
  68. 0x02, 0x80, 0x01, 0xD4, 0x02, 0xA8, 0x0E, 0xA0, 0xEA, 0x05, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00,
  69. 0x02, 0x80, 0x01, 0x14, 0x03, 0xA8, 0x0A, 0xA0, 0xAA, 0x05, 0x54, 0x00, 0x00, 0x00, 0x00, 0x00,
  70. 0x03, 0x80, 0x01, 0xDC, 0x00, 0xB8, 0x0E, 0xE0, 0xEE, 0x05, 0xDC, 0x00, 0x00, 0x00, 0x00, 0x00,
  71. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  72. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  73. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  74. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  75. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  76. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  77. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  78. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  79. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  80. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  81. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x41, 0x08, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  82. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA2, 0x94, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  83. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA2, 0x94, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  84. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA2, 0x94, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  85. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA2, 0x94, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  86. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA2, 0x94, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  87. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA2, 0x94, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  88. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA2, 0x94, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  89. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA2, 0x94, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  90. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA2, 0x94, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  91. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0x14, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  92. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2A, 0x17, 0xD0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  93. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x08, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  94. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x07, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  95. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  96. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  97. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  98. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  99. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  100. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  101. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  102. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  103. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  104. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  105. };
  106. void setup(){
  107.   Serial.begin(9600);
  108.   pinMode(left, INPUT);                             // analog input for outside audio source
  109.     pinMode(right, INPUT);                             // analog input for outside audio source
  110.   display1.begin(SSD1306_SWITCHCAPVCC, 0x3C);                // needed for SSD1306 display1    3C
  111.   display1.clearDisplay();  // clears display from any library info displayed
  112.   
  113.   display2.begin(SSD1306_SWITCHCAPVCC, 0x3D);                // needed for SSD1306 display     3D
  114.   display2.clearDisplay();                                  // clears display from any library info displayed
  115. }
  116. void loop(){
  117.   unsigned long startMillis = millis();                    // start of sample window
  118.   unsigned int PeaktoPeakLeft = 0;                             // peak-to-peak level
  119.   unsigned int SignalMaxLeft = 0;
  120.   unsigned int SignalMinLeft = 1024;
  121.   unsigned int PeaktoPeakRight = 0;                             // peak-to-peak level
  122.   unsigned int SignalMaxRight = 0;
  123.   unsigned int SignalMinRight = 1024;
  124.   while ( millis() - startMillis < sampleWindow ){
  125.     sampleLeft = analogRead(left);
  126.     sampleRight = analogRead(right);
  127.     if (sampleLeft < 1024) {
  128.       if (sampleLeft > SignalMaxLeft){
  129.         SignalMaxLeft = sampleLeft;                                // saves just the max levels
  130.       }
  131.       else if (sampleLeft < SignalMinLeft){
  132.         SignalMinLeft = sampleLeft;                                // saves just the min levels
  133.       }
  134.     }
  135.     if (sampleRight < 1024) {
  136.       if (sampleRight > SignalMaxRight){
  137.         SignalMaxRight = sampleRight;                                // saves just the max levels
  138.       }
  139.       else if (sampleRight < SignalMinRight){
  140.         SignalMinRight = sampleRight;                                // saves just the min levels
  141.       }
  142.     }
  143.    
  144.   }
  145.   PeaktoPeakLeft = SignalMaxLeft - SignalMinLeft;                      // max - min = peak-peak amplitude
  146.   PeaktoPeakRight = SignalMaxRight - SignalMinRight;                   // max - min = peak-peak amplitude
  147.    if (PeaktoPeakLeft > PeakLeft){
  148.         PeakLeft = PeaktoPeakLeft;// saves just the min levels
  149.       }else if(PeaktoPeakLeft < PeakLeft){
  150.         fallTimeLeft = ((PeakLeft - PeaktoPeakLeft) / 2);
  151.         PeakLeft = PeakLeft-fallTimeLeft;
  152.       }
  153.    if (PeaktoPeakRight > PeakRight){
  154.         PeakRight = PeaktoPeakRight;// saves just the min levels
  155.       }else if(PeaktoPeakRight < PeakRight){
  156.         fallTimeRight = ((PeakRight - PeaktoPeakRight) / 2);
  157.         PeakRight = PeakRight-fallTimeRight;
  158.       }
  159.    
  160.   MeterValueLeft = PeakLeft ;              // convert volts to arrow information sensitivity
  161.   MeterValueRight = PeakRight ;              // convert volts to arrow information sensitivity
  162. drawleft();
  163. drawright();
  164. }
  165. void drawleft(){
  166.   
  167.   MeterValueLeft = MeterValueLeft - 34;                            // shifts needle to zero position
  168.   display1.clearDisplay();                                  // refresh display for next step
  169.   display1.drawBitmap(0, 0, VUMeter, 128, 64, WHITE);       // draws background white
  170.   int a1 = (hMeter + (sin(MeterValueLeft / 57.296) * rMeter)); // meter needle horizontal coordinate
  171.   int a2 = (vMeter - (cos(MeterValueLeft / 57.296) * rMeter)); // meter needle vertical coordinate
  172.   
  173. display1.drawLine(a1-2, a2, hMeter-1, vMeter, BLACK);         // draws needle
  174. display1.drawLine(a1-1, a2, hMeter-1, vMeter, WHITE);         // draws needle  
  175. display1.drawLine(a1, a2, hMeter, vMeter, WHITE);         // draws needle
  176. display1.drawLine(a1+1, a2, hMeter+1, vMeter, WHITE);         // draws needle  
  177. display1.drawLine(a1+2, a2, hMeter+1, vMeter, BLACK);         // draws needle
  178.   display1.display();
  179. }
  180. void drawright(){
  181.   
  182.   MeterValueRight = MeterValueRight - 44;                            // shifts needle to zero position
  183.   display2.clearDisplay();                                  // refresh display for next step
  184.   display2.drawBitmap(0, 0, VUMeter, 128, 64, WHITE);       // draws background white
  185.   int a1 = (hMeter + (sin(MeterValueRight / 57.296) * rMeter)); // meter needle horizontal coordinate
  186.   int a2 = (vMeter - (cos(MeterValueRight / 57.296) * rMeter)); // meter needle vertical coordinate
  187.   display1.drawLine(a1-2, a2, hMeter-1, vMeter, BLACK);         // draws needle
  188. display1.drawLine(a1-1, a2, hMeter-1, vMeter, WHITE);         // draws needle  
  189. display1.drawLine(a1, a2, hMeter, vMeter, WHITE);         // draws needle
  190. display1.drawLine(a1+1, a2, hMeter+1, vMeter, WHITE);         // draws needle  
  191. display1.drawLine(a1+2, a2, hMeter+1, vMeter, BLACK);         // draws needle
  192.   display2.display();
  193. }
复制代码

回复

使用道具 举报

驴友花雕  中级技神
 楼主|

发表于 5 小时前

【Arduino 动手做】I2C OLED 上的 DIY 模拟式立体声 VU 表

【Arduino 动手做】I2C OLED 上的 DIY 模拟式立体声 VU 表
项目链接:https://www.hackster.io/mircemk/ ... -on-i2c-oled-00aca7
项目作者:北马其顿 米尔塞姆克(Mirko Pavleski)

项目视频 :https://www.youtube.com/watch?v=Wsuehxhob-c
项目代码:
CODE 弧标尺,单屏:
https://www.hackster.io/code_files/532492/download
CODE 线性刻度,立体声双屏:
https://www.hackster.io/code_files/532493/download

【Arduino 动手做】I2C OLED 上的 DIY 模拟式立体声 VU 表图2

【Arduino 动手做】I2C OLED 上的 DIY 模拟式立体声 VU 表图1

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4 备案 沪公网安备31011502402448

© 2013-2025 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail