Building an Arduino controlled OLED display VU meter, Part 7.
This part will teach you to code stereo VU display and different ways of VU presentation.
On the following arduino IDE code replace [ and ] with the respective angled brackets since youtube does not allow angled brackets in the description. All the "include" commands use angled brackets on the parameter as can be seen on the video.
Change also the line "for (int i=1;i [ samples;i++) {"
-------------------------------------------------------------------------------------------------------------
#include [SPI.h]
#include [Wire.h]
#include [Adafruit_GFX.h]
#include [Adafruit_SH110X.h]
#define i2c_Address 0x3c
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1 // QT-PY / XIAO
Adafruit_SH1106G display = Adafruit_SH1106G(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
int audioR = 0;
int audioL = 0;
int maxaudioR = 0;
int maxaudioL = 0;
int maxaudiopR = 0;
int maxaudiopL = 0;
int samples = 200;
int sensitivity = 400;
float smooth = 5; // -very smooth high up to 9--,--not smooth, low up to 1-
void setup() {
// put your setup code here, to run once:
analogReference(INTERNAL);
Serial.begin(9600);
analogRead(A0);
analogRead(A1);
display.begin(i2c_Address, true); // Address 0x3C default
delay(2000);
display.clearDisplay();
}
void loop() {
//audio = analogRead(A0);
maxaudioL = 0;
maxaudioR = 0;
for (int i=1;i [ samples;i++) {
audioR = analogRead(A0);
audioL = analogRead(A1);
maxaudioR = max(maxaudioR,audioR);
maxaudioL = max(maxaudioL,audioL);
}
maxaudioR = map(maxaudioR, 20, sensitivity, 0, 63);
maxaudioL = map(maxaudioL, 20, sensitivity, 0, 63);
maxaudioR = (maxaudiopR * (smooth/10)) + (maxaudioR * (1-(smooth/10)));
maxaudioL = (maxaudiopL * (smooth/10)) + (maxaudioL * (1-(smooth/10)));
display.clearDisplay();
//delay(10);
//Serial.println(maxaudio);
//display.drawPixel(10,5,SH110X_WHITE);
display.drawLine(55,20,70,20,SH110X_WHITE);
//Display R channel
display.drawLine(127,32,80,64-maxaudioR,SH110X_WHITE);
//display.fillRect(0,10,maxaudioR,10,SH110X_WHITE);
//Display L channel
display.drawLine(0,32,50,64-maxaudioL,SH110X_WHITE);
//display.fillRect(0,30,maxaudioL,10,SH110X_WHITE);
// display.clearDisplay();
//display.fillRect(0,55,(maxaudioR + maxaudioL)/2,5,SH110X_WHITE);
display.display();
//delay(20);
maxaudiopR = maxaudioR;
maxaudiopL = maxaudioL;
}
Негізгі бет OLED VU METER with Arduino - Part 7 - stereo display
Пікірлер: 2